From 216de4d123953d737a148b4a81f7ec3ed9a5e6ff Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Wed, 6 Mar 2024 23:05:13 +0530 Subject: [PATCH] fix: Conversation assignment notification title (#9071) --- app/models/notification.rb | 4 +++- spec/models/notification_spec.rb | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index c7f8d6a2d..25740b16a 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -106,8 +106,10 @@ class Notification < ApplicationRecord case notification_type when 'conversation_creation' message_body(conversation.messages.first) - when 'assigned_conversation_new_message', 'participating_conversation_new_message', 'conversation_assignment', 'conversation_mention' + when 'assigned_conversation_new_message', 'participating_conversation_new_message', 'conversation_mention' message_body(secondary_actor) + when 'conversation_assignment' + message_body(conversation.messages.incoming.last) else '' end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 087e245f0..282b316ee 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -76,6 +76,13 @@ has been assigned to you" expect(notification.push_message_body).to eq "#{message.sender.name}: #{message.content.truncate_words(10)}" end + it 'returns appropriate body suited for the notification type conversation_assignment' do + conversation = create(:conversation) + message = create(:message, sender: create(:user), content: Faker::Lorem.paragraphs(number: 2), conversation: conversation) + notification = create(:notification, notification_type: 'conversation_assignment', primary_actor: conversation, secondary_actor: message) + expect(notification.push_message_body).to eq "#{message.sender.name}: #{message.content.truncate_words(10)}" + end + it 'returns appropriate body suited for the notification type assigned_conversation_new_message' do conversation = create(:conversation) message = create(:message, sender: create(:user), content: Faker::Lorem.paragraphs(number: 2), conversation: conversation)