bug: Fix emails if assignee is nil (#1106)

This commit is contained in:
Pranav Raj S 2020-07-31 15:57:19 +05:30 committed by GitHub
parent 4b773f2a0e
commit 1dd3573c39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View file

@ -49,6 +49,10 @@ class ConversationReplyMailer < ApplicationMailer
private private
def assignee_name
@assignee_name ||= @agent&.available_name || 'Notifications'
end
def mail_subject def mail_subject
subject_line = I18n.t('conversations.reply.email_subject') subject_line = I18n.t('conversations.reply.email_subject')
"[##{@conversation.display_id}] #{subject_line}" "[##{@conversation.display_id}] #{subject_line}"
@ -56,7 +60,7 @@ class ConversationReplyMailer < ApplicationMailer
def reply_email def reply_email
if inbound_email_enabled? if inbound_email_enabled?
"#{@agent.available_name} <reply+#{@conversation.uuid}@#{current_domain}>" "#{assignee_name} <reply+#{@conversation.uuid}@#{current_domain}>"
else else
@agent&.email @agent&.email
end end
@ -64,9 +68,9 @@ class ConversationReplyMailer < ApplicationMailer
def from_email def from_email
if inbound_email_enabled? if inbound_email_enabled?
"#{@agent.available_name} <#{account_support_email}>" "#{assignee_name} <#{account_support_email}>"
else else
"#{@agent.available_name} <#{ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')}>" "#{assignee_name} <#{ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')}>"
end end
end end

View file

@ -33,6 +33,16 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
end end
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 context 'without summary' do
let(:conversation) { create(:conversation, assignee: agent, account: account).reload } let(:conversation) { create(:conversation, assignee: agent, account: account).reload }
let(:message_1) { create(:message, conversation: conversation, account: account, content: 'Outgoing Message 1').reload } let(:message_1) { create(:message, conversation: conversation, account: account, content: 'Outgoing Message 1').reload }