From 1dd3573c39e55b462faf205ac6b9acf1c4500f9b Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Fri, 31 Jul 2020 15:57:19 +0530 Subject: [PATCH] bug: Fix emails if assignee is nil (#1106) --- app/mailers/conversation_reply_mailer.rb | 10 +++++++--- spec/mailers/conversation_reply_mailer_spec.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/mailers/conversation_reply_mailer.rb b/app/mailers/conversation_reply_mailer.rb index 33e93d1a6..82c5b63e6 100644 --- a/app/mailers/conversation_reply_mailer.rb +++ b/app/mailers/conversation_reply_mailer.rb @@ -49,6 +49,10 @@ class ConversationReplyMailer < ApplicationMailer private + def assignee_name + @assignee_name ||= @agent&.available_name || 'Notifications' + end + def mail_subject subject_line = I18n.t('conversations.reply.email_subject') "[##{@conversation.display_id}] #{subject_line}" @@ -56,7 +60,7 @@ class ConversationReplyMailer < ApplicationMailer def reply_email if inbound_email_enabled? - "#{@agent.available_name} " + "#{assignee_name} " else @agent&.email end @@ -64,9 +68,9 @@ class ConversationReplyMailer < ApplicationMailer def from_email if inbound_email_enabled? - "#{@agent.available_name} <#{account_support_email}>" + "#{assignee_name} <#{account_support_email}>" else - "#{@agent.available_name} <#{ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')}>" + "#{assignee_name} <#{ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')}>" end end diff --git a/spec/mailers/conversation_reply_mailer_spec.rb b/spec/mailers/conversation_reply_mailer_spec.rb index 64e08136f..3761f02b9 100644 --- a/spec/mailers/conversation_reply_mailer_spec.rb +++ b/spec/mailers/conversation_reply_mailer_spec.rb @@ -33,6 +33,16 @@ RSpec.describe ConversationReplyMailer, type: :mailer do end end + context 'without assignee' do + let(:conversation) { create(:conversation, assignee: nil) } + let(:message) { create(:message, conversation: conversation) } + let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now } + + it 'has correct name' do + expect(mail[:from].display_names).to eq(['Notifications']) + end + end + context 'without summary' do let(:conversation) { create(:conversation, assignee: agent, account: account).reload } let(:message_1) { create(:message, conversation: conversation, account: account, content: 'Outgoing Message 1').reload }