chore: Automation bug fix (#4442)
This commit is contained in:
@@ -259,7 +259,7 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'returns for cloned automation_rule for account' do
|
||||
it 'returns for updated automation_rule for account' do
|
||||
params = { name: 'Update name' }
|
||||
expect(account.automation_rules.count).to eq(1)
|
||||
|
||||
@@ -271,6 +271,20 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
|
||||
body = JSON.parse(response.body, symbolize_names: true)
|
||||
expect(body[:payload][:name]).to eq('Update name')
|
||||
end
|
||||
|
||||
it 'returns for updated active flag for automation_rule' do
|
||||
expect(automation_rule.active).to eq(true)
|
||||
params = { active: false }
|
||||
|
||||
patch "/api/v1/accounts/#{account.id}/automation_rules/#{automation_rule.id}",
|
||||
headers: administrator.create_new_auth_token,
|
||||
params: params
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
body = JSON.parse(response.body, symbolize_names: true)
|
||||
expect(body[:payload][:active]).to eq(false)
|
||||
expect(automation_rule.reload.active).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -50,125 +50,6 @@ describe AutomationRuleListener do
|
||||
automation_rule.save
|
||||
end
|
||||
|
||||
describe '#conversation_status_changed' do
|
||||
context 'when rule matches' do
|
||||
it 'triggers automation rule send webhook events' do
|
||||
payload = conversation.webhook_data.merge(event: "automation_event: #{automation_rule.event_name}")
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
expect(WebhookJob).to receive(:perform_later).with('https://www.example.com', payload).once
|
||||
|
||||
listener.conversation_status_changed(event)
|
||||
end
|
||||
|
||||
it 'triggers automation rule to assign team' do
|
||||
expect(conversation.team_id).not_to eq(team.id)
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_status_changed(event)
|
||||
|
||||
conversation.reload
|
||||
expect(conversation.team_id).to eq(team.id)
|
||||
end
|
||||
|
||||
it 'triggers automation rule to add label' do
|
||||
expect(conversation.labels).to eq([])
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_status_changed(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
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_status_changed(event)
|
||||
|
||||
conversation.reload
|
||||
|
||||
expect(conversation.assignee).to eq(user_1)
|
||||
end
|
||||
|
||||
it 'triggers automation rule send message to the contacts' do
|
||||
expect(conversation.messages).to be_empty
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_status_changed(event)
|
||||
|
||||
conversation.reload
|
||||
|
||||
expect(conversation.messages.first.content).to eq('Send this message.')
|
||||
end
|
||||
|
||||
it 'triggers automation rule changes status to snoozed' do
|
||||
expect(conversation.status).to eq('resolved')
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_status_changed(event)
|
||||
|
||||
conversation.reload
|
||||
|
||||
expect(conversation.status).to eq('snoozed')
|
||||
end
|
||||
|
||||
it 'triggers automation rule send email transcript to the mentioned email' do
|
||||
mailer = double
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_status_changed(event)
|
||||
|
||||
conversation.reload
|
||||
|
||||
allow(mailer).to receive(:conversation_transcript)
|
||||
end
|
||||
|
||||
it 'triggers automation rule send email to the team' do
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_status_changed(event)
|
||||
end
|
||||
|
||||
it 'triggers automation rule send attachments in messages' do
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_status_changed(event)
|
||||
|
||||
conversation.reload
|
||||
|
||||
expect(conversation.messages.last.attachments.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#conversation_updated with contacts attributes' do
|
||||
before do
|
||||
conversation.contact.update!(custom_attributes: { customer_type: 'platinum', signed_in_at: '2022-01-19' },
|
||||
|
||||
@@ -55,7 +55,7 @@ RSpec.describe Conversation, type: :model do
|
||||
# send_events
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::CONVERSATION_CREATED, kind_of(Time), conversation: conversation, notifiable_assignee_change: false,
|
||||
changed_attributes: nil)
|
||||
changed_attributes: nil, performed_by: nil)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -121,16 +121,16 @@ RSpec.describe Conversation, type: :model do
|
||||
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::CONVERSATION_RESOLVED, kind_of(Time), conversation: conversation, notifiable_assignee_change: true,
|
||||
changed_attributes: status_change)
|
||||
changed_attributes: status_change, performed_by: nil)
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::CONVERSATION_READ, kind_of(Time), conversation: conversation, notifiable_assignee_change: true,
|
||||
changed_attributes: nil)
|
||||
changed_attributes: nil, performed_by: nil)
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::ASSIGNEE_CHANGED, kind_of(Time), conversation: conversation, notifiable_assignee_change: true,
|
||||
changed_attributes: nil)
|
||||
changed_attributes: nil, performed_by: nil)
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::CONVERSATION_UPDATED, kind_of(Time), conversation: conversation, notifiable_assignee_change: true,
|
||||
changed_attributes: changed_attributes)
|
||||
changed_attributes: changed_attributes, performed_by: nil)
|
||||
end
|
||||
|
||||
it 'will not run conversation_updated event for empty updates' do
|
||||
|
||||
Reference in New Issue
Block a user