fix: Set message sender to macros excution (#5769)

This commit is contained in:
Tejaswini Chile
2022-10-31 19:33:12 +05:30
committed by GitHub
parent 2073a23d5c
commit a0606d36f6
2 changed files with 49 additions and 14 deletions

View File

@@ -3,6 +3,7 @@ class Macros::ExecutionService < ActionService
super(conversation)
@macro = macro
@account = macro.account
@user = user
Current.user = user
end
@@ -27,7 +28,7 @@ class Macros::ExecutionService < ActionService
params = { content: message[0], private: false }
# Added reload here to ensure conversation us persistent with the latest updates
mb = Messages::MessageBuilder.new(nil, @conversation.reload, params)
mb = Messages::MessageBuilder.new(@user, @conversation.reload, params)
mb.perform
end
@@ -43,7 +44,7 @@ class Macros::ExecutionService < ActionService
params = { content: nil, private: false, attachments: blobs }
# Added reload here to ensure conversation us persistent with the latest updates
mb = Messages::MessageBuilder.new(nil, @conversation.reload, params)
mb = Messages::MessageBuilder.new(@user, @conversation.reload, params)
mb.perform
end
end

View File

@@ -247,9 +247,33 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
end
context 'when it is an authenticated user' do
it 'execute the macro' do
context 'when execute the macro' do
it 'send the message with sender' do
expect(conversation.messages).to be_empty
perform_enqueued_jobs do
post "/api/v1/accounts/#{account.id}/macros/#{macro.id}/execute",
params: { conversation_ids: [conversation.display_id] },
headers: administrator.create_new_auth_token
end
expect(conversation.messages.chat.last.content).to eq('Send this message.')
expect(conversation.messages.chat.last.sender).to eq(administrator)
end
it 'Assign the agent' do
expect(conversation.assignee).to be_nil
perform_enqueued_jobs do
post "/api/v1/accounts/#{account.id}/macros/#{macro.id}/execute",
params: { conversation_ids: [conversation.display_id] },
headers: administrator.create_new_auth_token
end
expect(conversation.messages.activity.last.content).to eq("Assigned to #{user_1.name} by #{administrator.name}")
end
it 'Assign the labels' do
expect(conversation.labels).to be_empty
perform_enqueued_jobs do
@@ -258,10 +282,20 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
headers: administrator.create_new_auth_token
end
expect(conversation.reload.label_list).to match_array(%w[support priority_customer])
end
it 'Update the status' do
expect(conversation.reload.status).to eql('open')
perform_enqueued_jobs do
post "/api/v1/accounts/#{account.id}/macros/#{macro.id}/execute",
params: { conversation_ids: [conversation.display_id] },
headers: administrator.create_new_auth_token
end
expect(conversation.reload.status).to eql('snoozed')
expect(conversation.messages.chat.last.content).to eq('Send this message.')
expect(conversation.label_list).to match_array(%w[support priority_customer])
expect(conversation.messages.activity.last.content).to eq("Assigned to #{user_1.name} by #{administrator.name}")
end
end
end
end