From ffec42751334bdd6f180f664395f9f8baa9ee554 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Fri, 22 Jul 2022 15:37:24 +0530 Subject: [PATCH] fix: mention notification mail for empty contact name (#5091) --- app/drops/conversation_drop.rb | 2 +- .../conversation_notifications_mailer_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/drops/conversation_drop.rb b/app/drops/conversation_drop.rb index ffd664659..d77e150c2 100644 --- a/app/drops/conversation_drop.rb +++ b/app/drops/conversation_drop.rb @@ -6,7 +6,7 @@ class ConversationDrop < BaseDrop end def contact_name - @obj.try(:contact).name.capitalize || 'Customer' + @obj.try(:contact).name.try(:capitalize) || 'Customer' end def recent_messages diff --git a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb index 1186d7cc9..a4e00204d 100644 --- a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb +++ b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb @@ -39,9 +39,17 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile end describe 'conversation_mention' do + let(:contact) { create(:contact, name: nil, account: account) } let(:another_agent) { create(:user, email: 'agent2@example.com', account: account) } let(:message) { create(:message, conversation: conversation, account: account, sender: another_agent) } let(:mail) { described_class.with(account: account).conversation_mention(message, agent).deliver_now } + let(:contact_inbox) { create(:contact_inbox, account: account, inbox: conversation.inbox) } + + before do + create(:message, conversation: conversation, account: account, sender: contact) + create(:message, conversation: conversation, account: account, sender: contact) + create(:message, conversation: conversation, account: account, sender: contact) + end it 'renders the subject' do expect(mail.subject).to eq("#{agent.available_name}, You have been mentioned in conversation [ID - #{conversation.display_id}]") @@ -54,6 +62,12 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile it 'renders the senders name' do expect(mail.body.encoded).to match("You've been mentioned in a conversation. #{another_agent.display_name} wrote:") end + + it 'renders Customer if contacts name not available in the conversation' do + expect(contact.name).to be_nil + expect(conversation.recent_messages).not_to be_empty + expect(mail.body.encoded).to match('Incoming Message') + end end describe 'assigned_conversation_new_message' do