From 41ffd718d5ebd4f2a26c8073d5bf1e7851f0a091 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Thu, 22 Feb 2024 10:49:57 +0530 Subject: [PATCH] fixes --- app/models/notification.rb | 14 +++++--------- spec/models/notification_spec.rb | 15 +++++++-------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 6da3605fa..c96e4a8f0 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -95,17 +95,13 @@ class Notification < ApplicationRecord def push_message_title case notification_type when 'conversation_creation' - I18n.t('notifications.notification_title.conversation_creation', display_id: conversation.display_id, inbox_name: primary_actor.inbox.name) + conversation_creation_message_content when 'conversation_assignment' I18n.t('notifications.notification_title.conversation_assignment', display_id: conversation.display_id) when 'assigned_conversation_new_message', 'participating_conversation_new_message' - I18n.t( - 'notifications.notification_title.assigned_conversation_new_message', - display_id: conversation.display_id, - content: content - ) + message_created_message_content when 'conversation_mention' - "[##{conversation&.display_id}] #{transform_user_mention_content content}" + mention_content else '' end @@ -116,11 +112,11 @@ class Notification < ApplicationRecord end def conversation_creation_message_content - "#{conversation.messages.first&.sender&.name}: #{conversation.messages.first&.content}" + "#{conversation.messages.first&.sender&.name}: #{content}" end def message_created_message_content - "#{secondary_actor&.sender&.name}: #{secondary_actor&.content}" + "#{secondary_actor&.sender&.name}: #{content}" end def mention_content diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index cb3679290..1ae86700e 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -23,9 +23,10 @@ RSpec.describe Notification do context 'when push_title is called' do it 'returns appropriate title suited for the notification type conversation_creation' do - notification = create(:notification, notification_type: 'conversation_creation') - expect(notification.push_message_title).to eq "[New conversation] - ##{notification.primary_actor.display_id} has\ - been created in #{notification.primary_actor.inbox.name}" + conversation = create(:conversation) + message = create(:message, sender: create(:user), content: Faker::Lorem.paragraphs(number: 2), conversation: conversation) + notification = create(:notification, notification_type: 'conversation_creation', primary_actor: conversation) + expect(notification.push_message_title).to eq "#{message.sender.name}: #{message.content}" end it 'returns appropriate title suited for the notification type conversation_assignment' do @@ -39,8 +40,7 @@ RSpec.describe Notification do notification = create(:notification, notification_type: 'assigned_conversation_new_message', primary_actor: message.conversation, secondary_actor: message) - expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} \ -#{message.content.truncate_words(10)}" + expect(notification.push_message_title).to eq "#{message.sender.name}: #{message.content.truncate_words(10)}" end it 'returns appropriate title suited for the notification type assigned_conversation_new_message when attachment message' do @@ -100,8 +100,7 @@ Hey @John, @Alisha Peter can you check this ticket?" content: 'Hey [@John](mention://user/1/john), [@Alisha Peter](mention://user/2/alisha) can you check this ticket?' ) notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message.conversation, secondary_actor: message) - - expect(notification.push_message_title).to eq "[##{message.conversation.display_id}] Hey @John, @Alisha Peter can you check this ticket?" + expect(notification.push_message_title).to eq "#{message.sender.name}: Hey @John, @Alisha Peter can you check this ticket?" end it 'returns appropriate title suited for the notification type conversation_mention if username contains white space' do @@ -111,7 +110,7 @@ Hey @John, @Alisha Peter can you check this ticket?" content: 'Hey [@John Peter](mention://user/1/john%20K) please check this?' ) notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message.conversation, secondary_actor: message) - expect(notification.push_message_title).to eq "[##{message.conversation.display_id}] Hey @John Peter please check this?" + expect(notification.push_message_title).to eq "#{message.sender.name}: Hey @John Peter please check this?" end it 'calls remove duplicate notification job' do