fix: Add Attachment endpoint to save file against automation rule (#4480)
Co-authored-by: fayazara <fayazara@gmail.com> Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -133,29 +133,35 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
|
||||
|
||||
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]
|
||||
|
||||
expect(account.automation_rules.count).to eq(0)
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/automation_rules/attach_file",
|
||||
headers: administrator.create_new_auth_token,
|
||||
params: { attachment: file }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
blob = JSON.parse(response.body)
|
||||
|
||||
expect(blob['blob_key']).to be_present
|
||||
expect(blob['blob_id']).to be_present
|
||||
|
||||
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
|
||||
action_name: :send_attachment,
|
||||
action_params: [blob['blob_id']]
|
||||
}
|
||||
]
|
||||
|
||||
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)
|
||||
@@ -163,32 +169,36 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
|
||||
|
||||
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]
|
||||
file_2 = fixture_file_upload(Rails.root.join('spec/assets/sample.png'), 'image/png')
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/automation_rules/attach_file",
|
||||
headers: administrator.create_new_auth_token,
|
||||
params: { attachment: file_1 }
|
||||
|
||||
blob_1 = JSON.parse(response.body)
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/automation_rules/attach_file",
|
||||
headers: administrator.create_new_auth_token,
|
||||
params: { attachment: file_2 }
|
||||
|
||||
blob_2 = JSON.parse(response.body)
|
||||
|
||||
params[:actions] = [
|
||||
{
|
||||
action_name: :send_message,
|
||||
action_params: ['Welcome to the chatwoot platform.']
|
||||
action_name: :send_attachment,
|
||||
action_params: [blob_1['blob_id']]
|
||||
},
|
||||
{
|
||||
action_name: :update_additional_attributes,
|
||||
action_params: [{ intiated_at: '2021-12-03 17:25:26.844536 +0530' }]
|
||||
},
|
||||
{
|
||||
action_name: :send_attachments
|
||||
action_name: :send_attachment,
|
||||
action_params: [blob_2['blob_id']]
|
||||
}
|
||||
]
|
||||
|
||||
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
|
||||
|
||||
@@ -128,6 +128,15 @@ describe AutomationRuleListener do
|
||||
expect(conversation.messages.first.content).to eq('Send this message.')
|
||||
end
|
||||
|
||||
it 'triggers automation rule to mute conversation' do
|
||||
expect(conversation).not_to be_muted
|
||||
|
||||
listener.conversation_updated(event)
|
||||
|
||||
conversation.reload
|
||||
expect(conversation).to be_muted
|
||||
end
|
||||
|
||||
it 'triggers automation_rule with contact standard attributes' do
|
||||
automation_rule.update!(
|
||||
conditions: [
|
||||
|
||||
Reference in New Issue
Block a user