Chore: Improve conversation auto resolution (#3405)

Fixes: #1583
This commit is contained in:
Shivam Chahar
2021-11-27 09:26:18 +05:30
committed by GitHub
parent 89f9f39e6e
commit a4ee8ee239
11 changed files with 75 additions and 85 deletions

View File

@@ -0,0 +1,18 @@
require 'rails_helper'
RSpec.describe Account::ConversationsResolutionSchedulerJob, type: :job do
subject(:job) { described_class.perform_later }
let!(:account) { create(:account) }
it 'enqueues the job' do
expect { job }.to have_enqueued_job(described_class)
.on_queue('scheduled_jobs')
end
it 'enqueues Conversations::ResolutionJob' do
account.update(auto_resolve_duration: 10)
expect(Conversations::ResolutionJob).to receive(:perform_later).with(account: account).once
described_class.perform_now
end
end

View File

@@ -1,34 +0,0 @@
require 'rails_helper'
RSpec.describe AutoResolveConversationsJob, type: :job do
subject(:job) { described_class.perform_later(conversation.id) }
let!(:account) { create(:account) }
let!(:conversation) { create(:conversation, account: account) }
it 'queues the job' do
expect { job }.to have_enqueued_job(described_class)
.with(conversation.id)
.on_queue('medium')
end
it 'does nothing when there is no auto resolve duration' do
described_class.perform_now(conversation.id)
expect(conversation.reload.status).to eq('open')
end
it 're-queues the job if there is still time left to allow inactivity' do
account.update(auto_resolve_duration: 10)
conversation.update(last_activity_at: 3.days.ago)
expect { described_class.perform_now(conversation.id) }.to have_enqueued_job(described_class)
.with(conversation.id)
.on_queue('medium')
end
it 'resolves the issue if time of inactivity is more than the auto resolve duration' do
account.update(auto_resolve_duration: 10)
conversation.update(last_activity_at: 13.days.ago)
described_class.perform_now(conversation.id)
expect(conversation.reload.status).to eq('resolved')
end
end

View File

@@ -0,0 +1,26 @@
require 'rails_helper'
RSpec.describe Conversations::ResolutionJob, type: :job do
subject(:job) { described_class.perform_later(account) }
let!(:account) { create(:account) }
let!(:conversation) { create(:conversation, account: account) }
it 'enqueues the job' do
expect { job }.to have_enqueued_job(described_class)
.with(account)
.on_queue('medium')
end
it 'does nothing when there is no auto resolve duration' do
described_class.perform_now(account: account)
expect(conversation.reload.status).to eq('open')
end
it 'resolves the issue if time of inactivity is more than the auto resolve duration' do
account.update(auto_resolve_duration: 10)
conversation.update(last_activity_at: 13.days.ago)
described_class.perform_now(account: account)
expect(conversation.reload.status).to eq('resolved')
end
end

View File

@@ -25,5 +25,10 @@ RSpec.describe TriggerScheduledItemsJob, type: :job do
expect(Conversations::ReopenSnoozedConversationsJob).to receive(:perform_later).once
described_class.perform_now
end
it 'triggers Account::ConversationsResolutionSchedulerJob' do
expect(Account::ConversationsResolutionSchedulerJob).to receive(:perform_later).once
described_class.perform_now
end
end
end