feat: Add send message, fix issues with message conditions (#4423)
Co-authored-by: Tejaswini <tejaswini@chatwoot.com>
This commit is contained in:
@@ -259,17 +259,41 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'returns for updated automation_rule for account' do
|
||||
params = { name: 'Update name' }
|
||||
let(:update_params) do
|
||||
{
|
||||
description: 'Update description',
|
||||
name: 'Update name',
|
||||
conditions: [
|
||||
{
|
||||
attribute_key: 'browser_language',
|
||||
filter_operator: 'equal_to',
|
||||
values: ['en'],
|
||||
query_operator: 'AND'
|
||||
}
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
action_name: :update_additional_attributes,
|
||||
action_params: [{ intiated_at: '2021-12-03 17:25:26.844536 +0530' }]
|
||||
}
|
||||
]
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
it 'returns for cloned automation_rule for account' do
|
||||
expect(account.automation_rules.count).to eq(1)
|
||||
expect(account.automation_rules.first.actions.size).to eq(4)
|
||||
|
||||
patch "/api/v1/accounts/#{account.id}/automation_rules/#{automation_rule.id}",
|
||||
headers: administrator.create_new_auth_token,
|
||||
params: params
|
||||
params: update_params
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
body = JSON.parse(response.body, symbolize_names: true)
|
||||
expect(body[:payload][:name]).to eq('Update name')
|
||||
expect(body[:payload][:description]).to eq('Update description')
|
||||
expect(body[:payload][:conditions].size).to eq(1)
|
||||
expect(body[:payload][:actions].size).to eq(1)
|
||||
end
|
||||
|
||||
it 'returns for updated active flag for automation_rule' do
|
||||
|
||||
@@ -30,10 +30,10 @@ describe AutomationRuleListener do
|
||||
automation_rule.update!(actions:
|
||||
[
|
||||
{
|
||||
'action_name' => 'send_email_to_team', 'action_params' => {
|
||||
'action_name' => 'send_email_to_team', 'action_params' => [{
|
||||
'message' => 'Please pay attention to this conversation, its from high priority customer',
|
||||
'team_ids' => [team.id]
|
||||
}
|
||||
}]
|
||||
},
|
||||
{ 'action_name' => 'assign_team', 'action_params' => [team.id] },
|
||||
{ 'action_name' => 'add_label', 'action_params' => %w[support priority_customer] },
|
||||
@@ -104,7 +104,7 @@ describe AutomationRuleListener do
|
||||
it 'triggers automation rule send email transcript to the mentioned email' do
|
||||
mailer = double
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_updated)
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_updated(event)
|
||||
|
||||
@@ -116,7 +116,7 @@ describe AutomationRuleListener do
|
||||
it 'triggers automation rule send message to the contacts' do
|
||||
expect(conversation.messages).to be_empty
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_updated)
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_updated(event)
|
||||
|
||||
@@ -202,7 +202,7 @@ describe AutomationRuleListener do
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_updated)
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_updated(event)
|
||||
|
||||
@@ -214,7 +214,7 @@ describe AutomationRuleListener do
|
||||
it 'triggers automation rule send email to the team' do
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_updated)
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_updated(event)
|
||||
end
|
||||
@@ -224,7 +224,7 @@ describe AutomationRuleListener do
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_updated)
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.conversation_updated(event)
|
||||
|
||||
@@ -256,7 +256,7 @@ describe AutomationRuleListener do
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:message_created)
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.message_created(event)
|
||||
|
||||
@@ -269,7 +269,7 @@ describe AutomationRuleListener do
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:message_created)
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.message_created(event)
|
||||
|
||||
@@ -281,7 +281,7 @@ describe AutomationRuleListener do
|
||||
expect(conversation.assignee).to be_nil
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:message_created)
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.message_created(event)
|
||||
|
||||
@@ -295,7 +295,7 @@ describe AutomationRuleListener do
|
||||
|
||||
automation_rule
|
||||
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:message_created)
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
|
||||
listener.message_created(event)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user