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

View File

@@ -247,21 +247,55 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
end end
context 'when it is an authenticated user' do context 'when it is an authenticated user' do
it 'execute the macro' do context 'when execute the macro' do
expect(conversation.messages).to be_empty it 'send the message with sender' do
expect(conversation.assignee).to be_nil expect(conversation.messages).to be_empty
expect(conversation.labels).to be_empty
perform_enqueued_jobs do perform_enqueued_jobs do
post "/api/v1/accounts/#{account.id}/macros/#{macro.id}/execute", post "/api/v1/accounts/#{account.id}/macros/#{macro.id}/execute",
params: { conversation_ids: [conversation.display_id] }, params: { conversation_ids: [conversation.display_id] },
headers: administrator.create_new_auth_token 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 end
expect(conversation.reload.status).to eql('snoozed') it 'Assign the agent' do
expect(conversation.messages.chat.last.content).to eq('Send this message.') expect(conversation.assignee).to be_nil
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}") 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
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.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')
end
end end
end end
end end