diff --git a/app/services/action_service.rb b/app/services/action_service.rb index 927d0ed1b..77f3c6b9a 100644 --- a/app/services/action_service.rb +++ b/app/services/action_service.rb @@ -52,6 +52,8 @@ class ActionService end def send_email_transcript(emails) + emails = emails[0].gsub(/\s+/, '').split(',') + emails.each do |email| ConversationReplyMailer.with(account: @conversation.account).conversation_transcript(@conversation, email)&.deliver_later end diff --git a/spec/listeners/automation_rule_listener_old_spec.rb b/spec/listeners/automation_rule_listener_old_spec.rb index 69154c592..68507ea76 100644 --- a/spec/listeners/automation_rule_listener_old_spec.rb +++ b/spec/listeners/automation_rule_listener_old_spec.rb @@ -121,18 +121,6 @@ describe AutomationRuleListener do expect(conversation.assignee).to eq(user_1) end - it 'triggers automation rule send email transcript to the mentioned email' do - mailer = double - - expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation) - - listener.conversation_updated(event) - - conversation.reload - - allow(mailer).to receive(:conversation_transcript) - end - it 'triggers automation rule send message to the contacts' do expect(conversation.messages).to be_empty @@ -253,15 +241,6 @@ describe AutomationRuleListener do expect(conversation.assignee).to eq(user_1) end - it 'triggers automation rule send email transcript to the mentioned email' do - mailer = double - expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation) - listener.conversation_updated(event) - conversation.reload - - allow(mailer).to receive(:conversation_transcript) - end - it 'triggers automation rule send email to the team' do message_delivery = instance_double(ActionMailer::MessageDelivery) @@ -457,15 +436,6 @@ describe AutomationRuleListener do expect(conversation.assignee).to eq(user_1) end - it 'triggers automation rule send email transcript to the mentioned email' do - mailer = double - expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation) - listener.conversation_opened(event) - conversation.reload - - allow(mailer).to receive(:conversation_transcript) - end - it 'triggers automation rule send email to the team' do message_delivery = instance_double(ActionMailer::MessageDelivery) @@ -577,15 +547,6 @@ describe AutomationRuleListener do expect(conversation.assignee).to eq(user_1) end - - it 'triggers automation rule send email transcript to the mentioned email' do - mailer = double - expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation) - listener.message_created(event) - conversation.reload - - allow(mailer).to receive(:conversation_transcript) - end end end @@ -616,17 +577,6 @@ describe AutomationRuleListener do end context 'when rule matches' do - it 'triggers automation rule send email transcript to the mentioned email' do - mailer = double - allow(ConversationReplyMailer).to receive(:with).and_return(mailer) - allow(mailer).to receive(:conversation_transcript) - - listener.message_created(event) - conversation.reload - - expect(mailer).to have_received(:conversation_transcript).with(conversation, 'new_agent@example.com') - end - it 'triggers automation rule send message to the contacts' do expect(conversation.messages.count).to eq(1) listener.message_created(event) @@ -710,18 +660,6 @@ describe AutomationRuleListener do end context 'when rule matches' do - it 'triggers automation rule send email transcript to the mentioned email' do - mailer = double - allow(ConversationReplyMailer).to receive(:with).and_return(mailer) - allow(mailer).to receive(:conversation_transcript) - - listener.conversation_created(event) - - conversation.reload - - expect(mailer).to have_received(:conversation_transcript).with(conversation, 'new_agent@example.com') - end - it 'triggers automation rule send message to the contacts' do expect(conversation.messages.count).to eq(1) @@ -781,15 +719,6 @@ describe AutomationRuleListener do let(:event) { Events::Base.new('message_created', Time.zone.now, { conversation: tweet, message: message }) } let!(:message) { create(:message, account: account, conversation: tweet, message_type: 'incoming') } - it 'triggers automation rule except send_message and send_attachment' do - mailer = double - allow(ConversationReplyMailer).to receive(:with).and_return(mailer) - allow(mailer).to receive(:conversation_transcript) - - listener.message_created(event) - expect(mailer).to have_received(:conversation_transcript).with(tweet, 'new_agent@example.com') - end - it 'does not triggers automation rule send message or send attachment' do expect(tweet.messages.count).to eq(1) diff --git a/spec/services/automation_rules/action_service_spec.rb b/spec/services/automation_rules/action_service_spec.rb index cb54c36b6..c95789399 100644 --- a/spec/services/automation_rules/action_service_spec.rb +++ b/spec/services/automation_rules/action_service_spec.rb @@ -87,5 +87,21 @@ RSpec.describe AutomationRules::ActionService do described_class.new(rule, account, conversation).perform end end + + describe '#perform with send_email_transcript action' do + before do + rule.actions << { action_name: 'send_email_transcript', action_params: ['contact@example.com, agent@example.com,agent1@example.com'] } + end + + it 'will send email to transcript to action params emails' do + mailer = double + allow(ConversationReplyMailer).to receive(:with).and_return(mailer) + allow(mailer).to receive(:conversation_transcript).with(conversation, 'contact@example.com') + allow(mailer).to receive(:conversation_transcript).with(conversation, 'agent@example.com') + allow(mailer).to receive(:conversation_transcript).with(conversation, 'agent1@example.com') + + described_class.new(rule, account, conversation).perform + end + end end end