From 8d45849d0c678ca5b03e983f8a360df62f67b231 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Fri, 12 Feb 2021 22:56:12 +0530 Subject: [PATCH] chore: Update notification Message Copy (#1685) --- app/models/notification.rb | 29 +++++++++++++++++------------ config/locales/en.yml | 6 ++++++ spec/models/notification_spec.rb | 29 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 91ed694a6..e29fb1f14 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -59,21 +59,26 @@ class Notification < ApplicationRecord end # TODO: move to a data presenter + # rubocop:disable Metrics/CyclomaticComplexity def push_message_title - if notification_type == 'conversation_creation' - return "A new conversation [ID -#{primary_actor.display_id}] has been created in #{primary_actor.inbox.name}" + case notification_type + when 'conversation_creation' + I18n.t('notifications.notification_title.conversation_creation', display_id: primary_actor.display_id, inbox_name: primary_actor.inbox.name) + when 'conversation_assignment' + I18n.t('notifications.notification_title.conversation_assignment', display_id: primary_actor.display_id) + when 'assigned_conversation_new_message' + I18n.t( + 'notifications.notification_title.assigned_conversation_new_message', + display_id: primary_actor.display_id, + content: primary_actor&.messages&.incoming&.last&.content + ) + when 'conversation_mention' + I18n.t('notifications.notification_title.conversation_mention', display_id: primary_actor.conversation.display_id, name: secondary_actor.name) + else + '' end - - return "A new conversation [ID -#{primary_actor.display_id}] has been assigned to you." if notification_type == 'conversation_assignment' - - return "New message in your assigned conversation [ID -#{primary_actor.display_id}]." if notification_type == 'assigned_conversation_new_message' - - if notification_type == 'conversation_mention' - return "You have been mentioned in conversation [ID -#{primary_actor.conversation.display_id}] by #{secondary_actor.name}" - end - - '' end + # rubocop:enable Metrics/CyclomaticComplexity private diff --git a/config/locales/en.yml b/config/locales/en.yml index b87bc7023..b8e0952d9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -45,6 +45,12 @@ en: reports: period: Reporting period %{since} to %{until} + notifications: + notification_title: + conversation_creation: "[New conversation] - #%{display_id} has been created in %{inbox_name}" + conversation_assignment: "[Assigned to you] - #%{display_id} has been assigned to you" + assigned_conversation_new_message: "[New message] - #%{display_id} %{content}" + conversation_mention: "You have been mentioned in conversation [ID - %{display_id}] by %{name}" conversations: messages: deleted: This message was deleted diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 7920df919..229cc12e0 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -18,4 +18,33 @@ RSpec.describe Notification do expect(described_class.all.last).to eq notification1 end end + + 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}" + end + + it 'returns appropriate title suited for the notification type conversation_assignment' do + notification = create(:notification, notification_type: 'conversation_assignment') + + expect(notification.push_message_title).to eq "[Assigned to you] - ##{notification.primary_actor.display_id} has been assigned to you" + end + + it 'returns appropriate title suited for the notification type assigned_conversation_new_message' do + notification = create(:notification, notification_type: 'assigned_conversation_new_message') + + expect(notification.push_message_title).to eq "[New message] - ##{notification.primary_actor.display_id} " + end + + it 'returns appropriate title suited for the notification type conversation_mention' do + message = create(:message, sender: create(:user)) + notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message, secondary_actor: message.sender) + + expect(notification.push_message_title).to eq "You have been mentioned in conversation [ID - #{message.conversation.display_id}] \ +by #{message.sender.name}" + end + end end