feat(ee): Add reporting events for bots (#9027)
Added a new event conversation_bot_resolved and added a job to auto resolve the bot conversations if there was no activity for the last 1 hour.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Account::ConversationsResolutionSchedulerJob, type: :job do
|
||||
let!(:account_with_bot) { create(:account) }
|
||||
let!(:account_without_bot) { create(:account) }
|
||||
let!(:inbox_with_bot) { create(:inbox, account: account_with_bot) }
|
||||
let!(:inbox_without_bot) { create(:inbox, account: account_without_bot) }
|
||||
let(:response_source) { create(:response_source, account: account_with_bot) }
|
||||
|
||||
before do
|
||||
skip_unless_response_bot_enabled_test_environment
|
||||
account_with_bot.enable_features!(:response_bot)
|
||||
create(:inbox_response_source, inbox: inbox_with_bot, response_source: response_source)
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
it 'enqueues resolution jobs only for inboxes with response bot enabled' do
|
||||
expect do
|
||||
described_class.perform_now
|
||||
end.to have_enqueued_job(ResponseBot::InboxPendingConversationsResolutionJob).with(inbox_with_bot).and have_enqueued_job.exactly(:once)
|
||||
end
|
||||
|
||||
it 'does not enqueue resolution jobs for inboxes without response bot enabled' do
|
||||
expect do
|
||||
described_class.perform_now
|
||||
end.not_to have_enqueued_job(ResponseBot::InboxPendingConversationsResolutionJob).with(inbox_without_bot)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,38 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ResponseBot::InboxPendingConversationsResolutionJob, type: :job do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
let!(:inbox) { create(:inbox) }
|
||||
let!(:resolvable_pending_conversation) { create(:conversation, inbox: inbox, last_activity_at: 2.hours.ago, status: :pending) }
|
||||
let!(:recent_pending_conversation) { create(:conversation, inbox: inbox, last_activity_at: 10.minutes.ago, status: :pending) }
|
||||
let!(:open_conversation) { create(:conversation, inbox: inbox, last_activity_at: 1.hour.ago, status: :open) }
|
||||
|
||||
before do
|
||||
stub_const('Limits::BULK_ACTIONS_LIMIT', 2)
|
||||
end
|
||||
|
||||
it 'queues the job' do
|
||||
expect { described_class.perform_later(inbox) }
|
||||
.to have_enqueued_job.on_queue('low')
|
||||
end
|
||||
|
||||
it 'resolves only the eligible pending conversations' do
|
||||
perform_enqueued_jobs { described_class.perform_later(inbox) }
|
||||
|
||||
expect(resolvable_pending_conversation.reload.status).to eq('resolved')
|
||||
expect(recent_pending_conversation.reload.status).to eq('pending')
|
||||
expect(open_conversation.reload.status).to eq('open')
|
||||
end
|
||||
|
||||
it 'creates an outgoing message for each resolved conversation' do
|
||||
# resolution message + system message
|
||||
expect { perform_enqueued_jobs { described_class.perform_later(inbox) } }
|
||||
.to change { resolvable_pending_conversation.messages.reload.count }.by(2)
|
||||
|
||||
resolved_conversation_messages = resolvable_pending_conversation.messages.map(&:content)
|
||||
expect(resolved_conversation_messages).to include(
|
||||
'Resolving the conversation as it has been inactive for a while. Please start a new conversation if you need further assistance.'
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user