Added event for conversation opened (#6412)
This commit is contained in:
@@ -420,6 +420,70 @@ describe AutomationRuleListener do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#conversation_opened' do
|
||||
before do
|
||||
conversation.update!(status: :open, team_id: team.id)
|
||||
automation_rule.update!(
|
||||
event_name: 'conversation_opened',
|
||||
name: 'Call actions conversation opened',
|
||||
description: 'Add labels, assign team after conversation updated',
|
||||
conditions: [{ attribute_key: 'team_id', filter_operator: 'equal_to', values: [team.id], query_operator: nil }.with_indifferent_access]
|
||||
)
|
||||
end
|
||||
|
||||
let!(:event) do
|
||||
Events::Base.new('conversation_opened', Time.zone.now, { conversation: conversation.reload })
|
||||
end
|
||||
|
||||
context 'when rule matches' do
|
||||
it 'triggers automation rule to add label' do
|
||||
expect(conversation.labels).to eq([])
|
||||
listener.conversation_opened(event)
|
||||
conversation.reload
|
||||
|
||||
expect(conversation.labels.pluck(:name)).to contain_exactly('support', 'priority_customer')
|
||||
end
|
||||
|
||||
it 'triggers automation rule to assign best agents' do
|
||||
expect(conversation.assignee).to be_nil
|
||||
listener.conversation_opened(event)
|
||||
conversation.reload
|
||||
|
||||
expect(conversation.assignee).to eq(user_1)
|
||||
end
|
||||
|
||||
it 'triggers automation rule send email transcript to the mentioned email' do
|
||||
mailer = double
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
listener.conversation_opened(event)
|
||||
conversation.reload
|
||||
|
||||
allow(mailer).to receive(:conversation_transcript)
|
||||
end
|
||||
|
||||
it 'triggers automation rule send email to the team' do
|
||||
message_delivery = instance_double(ActionMailer::MessageDelivery)
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation).with(
|
||||
conversation, team,
|
||||
'Please pay attention to this conversation, its from high priority customer'
|
||||
).and_return(message_delivery)
|
||||
allow(message_delivery).to receive(:deliver_now)
|
||||
|
||||
listener.conversation_opened(event)
|
||||
end
|
||||
|
||||
it 'triggers automation rule send message to the contacts' do
|
||||
expect(conversation.messages).to be_empty
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
listener.conversation_opened(event)
|
||||
conversation.reload
|
||||
|
||||
expect(conversation.messages.first.content).to eq('Send this message.')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#message_created event based on case in-sensitive filter' do
|
||||
before do
|
||||
automation_rule.update!(
|
||||
|
||||
Reference in New Issue
Block a user