chore: Change primary actor to Conversation for all the notification types. (#8435)

This commit is contained in:
Muhsin Keloth
2023-12-06 10:43:09 +05:30
committed by GitHub
parent 17faa6c3b2
commit 76711d95ff
12 changed files with 91 additions and 74 deletions

View File

@@ -0,0 +1,10 @@
require 'rails_helper'
RSpec.describe Migration::RemoveMessageNotifications do
subject(:job) { described_class.perform_later }
it 'enqueues the job' do
expect { job }.to have_enqueued_job(described_class)
.on_queue('scheduled_jobs')
end
end

View File

@@ -24,7 +24,6 @@ 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}"
end
@@ -37,7 +36,8 @@ RSpec.describe Notification do
it 'returns appropriate title suited for the notification type assigned_conversation_new_message' do
message = create(:message, sender: create(:user), content: Faker::Lorem.paragraphs(number: 2))
notification = create(:notification, notification_type: 'assigned_conversation_new_message', primary_actor: message)
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)}"
@@ -46,14 +46,16 @@ RSpec.describe Notification do
it 'returns appropriate title suited for the notification type assigned_conversation_new_message when attachment message' do
# checking content nil should be suffice for attachments
message = create(:message, sender: create(:user), content: nil)
notification = create(:notification, notification_type: 'assigned_conversation_new_message', primary_actor: message)
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} "
end
it 'returns appropriate title suited for the notification type participating_conversation_new_message' do
message = create(:message, sender: create(:user), content: Faker::Lorem.paragraphs(number: 2))
notification = create(:notification, notification_type: 'participating_conversation_new_message', primary_actor: message)
notification = create(:notification, notification_type: 'participating_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)}"
@@ -61,17 +63,16 @@ RSpec.describe Notification do
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)
notification = create(:notification, notification_type: 'participating_conversation_new_message', primary_actor: message.conversation,
secondary_actor: message)
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)
notification = create(:notification, notification_type: 'participating_conversation_new_message', primary_actor: message.conversation,
secondary_actor: message)
expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} \
Hey @John, @Alisha Peter can you check this ticket?"
@@ -79,15 +80,15 @@ Hey @John, @Alisha Peter can you check this ticket?"
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)
notification = create(:notification, notification_type: 'participating_conversation_new_message', primary_actor: message.conversation,
secondary_actor: message)
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)
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, can you check this ticket?"
end
@@ -98,7 +99,7 @@ Hey @John, @Alisha Peter can you check this ticket?"
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: 'conversation_mention', primary_actor: message, secondary_actor: message.sender)
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?"
end
@@ -109,8 +110,7 @@ Hey @John, @Alisha Peter can you check this ticket?"
create(:user),
content: 'Hey [@John Peter](mention://user/1/john%20K) please check this?'
)
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message, secondary_actor: message.sender)
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?"
end
end
@@ -125,11 +125,10 @@ Hey @John, @Alisha Peter can you check this ticket?"
it 'returns correct data for primary actor message' do
message = create(:message, sender: create(:user), content: Faker::Lorem.paragraphs(number: 2))
notification = create(:notification, notification_type: 'assigned_conversation_new_message', primary_actor: message)
notification = create(:notification, notification_type: 'assigned_conversation_new_message', primary_actor: message.conversation,
secondary_actor: message)
expect(notification.fcm_push_data[:primary_actor]).to eq({
'id' => notification.primary_actor.id,
'conversation_id' => notification.primary_actor.conversation.display_id
'id' => notification.primary_actor.display_id
})
end
end

View File

@@ -32,7 +32,8 @@ describe Messages::MentionService do
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'conversation_mention',
user: first_agent,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
end
end
@@ -55,11 +56,13 @@ describe Messages::MentionService do
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'conversation_mention',
user: second_agent,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'conversation_mention',
user: first_agent,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
end
it 'add the users to the participants list' do

View File

@@ -40,21 +40,24 @@ describe Messages::NewMessageNotificationService do
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'participating_conversation_new_message',
user: participating_agent_2,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
end
it 'creates notifications for assignee' do
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'assigned_conversation_new_message',
user: assignee,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
end
it 'will not create notifications for the user who created the message' do
expect(NotificationBuilder).not_to have_received(:new).with(notification_type: 'participating_conversation_new_message',
user: participating_agent_1,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
end
end
@@ -69,18 +72,21 @@ describe Messages::NewMessageNotificationService do
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'assigned_conversation_new_message',
user: assignee,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
end
it 'creates notifications for all participating users' do
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'participating_conversation_new_message',
user: participating_agent_1,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
expect(NotificationBuilder).to have_received(:new).with(notification_type: 'participating_conversation_new_message',
user: participating_agent_2,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
end
end
@@ -97,7 +103,8 @@ describe Messages::NewMessageNotificationService do
expect(NotificationBuilder).not_to have_received(:new).with(notification_type: 'assigned_conversation_new_message',
user: assignee,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
end
end
@@ -112,11 +119,13 @@ describe Messages::NewMessageNotificationService do
expect(NotificationBuilder).not_to have_received(:new).with(notification_type: 'participating_conversation_new_message',
user: assignee,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
expect(NotificationBuilder).not_to have_received(:new).with(notification_type: 'assigned_conversation_new_message',
user: assignee,
account: account,
primary_actor: message)
primary_actor: message.conversation,
secondary_actor: message)
end
end
end