From 2c85098698f06d2fd705646616ee39cff79a41c2 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Thu, 25 May 2023 18:18:56 +0530 Subject: [PATCH] fix: Mentions in assigned/participation notification(#7185) --- app/models/notification.rb | 2 +- spec/models/notification_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index eadb48032..8fad75618 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -101,7 +101,7 @@ class Notification < ApplicationRecord I18n.t( 'notifications.notification_title.assigned_conversation_new_message', display_id: conversation.display_id, - content: primary_actor&.content&.truncate_words(10) + content: transform_user_mention_content(primary_actor&.content&.truncate_words(10)) ) when 'conversation_mention' "[##{conversation&.display_id}] #{transform_user_mention_content primary_actor&.content}" diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 15894d2d7..71a6209ad 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -59,6 +59,32 @@ RSpec.describe Notification do #{message.content.truncate_words(10)}" end + it 'returns appropriate title suited for the notification type participating_conversation_new_message having mention' do + message = create(:message, sender: create(:user), content: 'Hey [@John](mention://user/1/john), can you check this ticket?') + notification = create(:notification, notification_type: 'participating_conversation_new_message', primary_actor: message, + secondary_actor: message.sender) + + expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} Hey @John, can you check this ticket?" + end + + it 'returns appropriate title suited for the notification type participating_conversation_new_message having multple mention' do + message = create(:message, sender: create(:user), + content: 'Hey [@John](mention://user/1/john), [@Alisha Peter](mention://user/2/alisha) can you check this ticket?') + notification = create(:notification, notification_type: 'participating_conversation_new_message', primary_actor: message, + secondary_actor: message.sender) + + expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} \ +Hey @John, @Alisha Peter can you check this ticket?" + end + + it 'returns appropriate title suited for the notification type participating_conversation_new_message if username contains white space' do + message = create(:message, sender: create(:user), content: 'Hey [@John Peter](mention://user/1/john%20K) please check this?') + notification = create(:notification, notification_type: 'participating_conversation_new_message', primary_actor: message, + secondary_actor: message.sender) + + expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} Hey @John Peter please check this?" + end + it 'returns appropriate title suited for the notification type conversation_mention' do message = create(:message, sender: create(:user), content: 'Hey [@John](mention://user/1/john), can you check this ticket?') notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message, secondary_actor: message.sender)