Feat: attachments automation (#4266)

This commit is contained in:
Tejaswini Chile
2022-03-30 08:08:58 +05:30
committed by GitHub
parent 3f2ac2042f
commit 15fd37b124
5 changed files with 135 additions and 15 deletions

View File

@@ -84,6 +84,23 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
}.with_indifferent_access
end
it 'throws an error for unknown attributes in condtions' do
expect(account.automation_rules.count).to eq(0)
params[:conditions] << {
attribute_key: 'unknown_attribute',
filter_operator: 'equal_to',
values: ['en'],
query_operator: 'AND'
}
post "/api/v1/accounts/#{account.id}/automation_rules",
headers: administrator.create_new_auth_token,
params: params
expect(response).to have_http_status(:unprocessable_entity)
expect(account.automation_rules.count).to eq(0)
end
it 'Saves for automation_rules for account with country_code and browser_language conditions' do
expect(account.automation_rules.count).to eq(0)
@@ -113,6 +130,67 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
expect(response).to have_http_status(:success)
expect(account.automation_rules.count).to eq(1)
end
it 'Saves file in the automation actions to send an attachments' do
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
params[:attachments] = [file]
params[:actions] = [
{
action_name: :send_message,
action_params: ['Welcome to the chatwoot platform.']
},
{
action_name: :update_additional_attributes,
action_params: [{ intiated_at: '2021-12-03 17:25:26.844536 +0530' }]
},
{
action_name: :send_attachments
}
]
expect(account.automation_rules.count).to eq(0)
post "/api/v1/accounts/#{account.id}/automation_rules",
headers: administrator.create_new_auth_token,
params: params
expect(response).to have_http_status(:success)
expect(account.automation_rules.count).to eq(1)
automation_rule = account.automation_rules.first
expect(automation_rule.files.presence).to be_truthy
expect(automation_rule.files.count).to eq(1)
end
it 'Saves files in the automation actions to send multiple attachments' do
file_1 = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
file_2 = fixture_file_upload(Rails.root.join('spec/assets/sample.pdf'), 'image/png')
params[:attachments] = [file_1, file_2]
params[:actions] = [
{
action_name: :send_message,
action_params: ['Welcome to the chatwoot platform.']
},
{
action_name: :update_additional_attributes,
action_params: [{ intiated_at: '2021-12-03 17:25:26.844536 +0530' }]
},
{
action_name: :send_attachments
}
]
expect(account.automation_rules.count).to eq(0)
post "/api/v1/accounts/#{account.id}/automation_rules",
headers: administrator.create_new_auth_token,
params: params
expect(response).to have_http_status(:success)
expect(account.automation_rules.count).to eq(1)
automation_rule = account.automation_rules.first
expect(automation_rule.files.presence).to be_truthy
expect(automation_rule.files.count).to eq(2)
end
end
end

View File

@@ -42,8 +42,12 @@ describe AutomationRuleListener do
{ 'action_name' => 'send_email_transcript', 'action_params' => 'new_agent@example.com' },
{ 'action_name' => 'mute_conversation', 'action_params' => nil },
{ 'action_name' => 'change_status', 'action_params' => ['snoozed'] },
{ 'action_name' => 'send_message', 'action_params' => ['Send this message.'] }
{ 'action_name' => 'send_message', 'action_params' => ['Send this message.'] },
{ 'action_name' => 'send_attachments' }
])
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
automation_rule.files.attach(file)
automation_rule.save
end
describe '#conversation_status_changed' do
@@ -112,7 +116,7 @@ describe AutomationRuleListener do
conversation.reload
expect(conversation.messages.last.content).to eq('Send this message.')
expect(conversation.messages.first.content).to eq('Send this message.')
end
it 'triggers automation rule changes status to snoozed' do
@@ -150,6 +154,18 @@ describe AutomationRuleListener do
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
@@ -225,7 +241,7 @@ describe AutomationRuleListener do
conversation.reload
expect(conversation.messages.last.content).to eq('Send this message.')
expect(conversation.messages.first.content).to eq('Send this message.')
end
it 'triggers automation_rule with contact standard attributes' do
@@ -333,7 +349,7 @@ describe AutomationRuleListener do
conversation.reload
expect(conversation.messages.last.content).to eq('Send this message.')
expect(conversation.messages.first.content).to eq('Send this message.')
end
end
end