feat: Revamp the notification title and content (#8988)

This commit is contained in:
Muhsin Keloth
2024-03-06 20:51:56 +05:30
committed by GitHub
parent 58dd2633ba
commit ef90b7a3d8
4 changed files with 95 additions and 69 deletions

View File

@@ -24,14 +24,14 @@ 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}"
expect(notification.push_message_title).to eq "A 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"
expect(notification.push_message_title).to eq "A conversation (##{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
@@ -39,8 +39,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 "A new message is created in conversation (##{notification.primary_actor.display_id})"
end
it 'returns appropriate title suited for the notification type assigned_conversation_new_message when attachment message' do
@@ -49,7 +48,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} "
expect(notification.push_message_title).to eq "A new message is created in conversation (##{notification.primary_actor.display_id})"
end
it 'returns appropriate title suited for the notification type participating_conversation_new_message' do
@@ -57,61 +56,61 @@ RSpec.describe Notification do
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)}"
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.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.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?"
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.conversation,
secondary_actor: message)
expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} Hey @John Peter please check this?"
expect(notification.push_message_title).to eq "A new message is created in conversation (##{notification.primary_actor.display_id})"
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.conversation, secondary_actor: message)
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?"
expect(notification.push_message_title).to eq "You have been mentioned in conversation (##{notification.primary_actor.display_id})"
end
end
context 'when push_message_body is called' do
it 'returns appropriate body suited for the notification type conversation_creation' do
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, secondary_actor: message)
expect(notification.push_message_body).to eq "#{message.sender.name}: #{message.content.truncate_words(10)}"
end
it 'returns appropriate title suited for the notification type conversation_mention having multiple mentions' 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: '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?"
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)
notification = create(:notification, notification_type: 'assigned_conversation_new_message', 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 title suited for the notification type conversation_mention 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: '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?"
it 'returns appropriate body suited for the notification type assigned_conversation_new_message when attachment message' do
conversation = create(:conversation)
message = create(:message, sender: create(:user), content: nil, conversation: conversation)
attachment = message.attachments.new(file_type: :image, account_id: message.account_id)
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
message.save!
notification = create(:notification, notification_type: 'assigned_conversation_new_message', primary_actor: conversation,
secondary_actor: message)
expect(notification.push_message_body).to eq "#{message.sender.name}: Attachment"
end
it 'returns appropriate body suited for the notification type participating_conversation_new_message having multple mention' do
conversation = create(:conversation)
message = create(:message, sender: create(:user),
content: 'Hey [@John](mention://user/1/john), [@Alisha Peter](mention://user/2/alisha) can you check this ticket?',
conversation: conversation)
notification = create(:notification, notification_type: 'participating_conversation_new_message', primary_actor: conversation,
secondary_actor: message)
expect(notification.push_message_body).to eq "#{message.sender.name}: Hey @John, @Alisha Peter can you check this ticket?"
end
it 'returns appropriate body suited for the notification type conversation_mention if username contains white space' do
conversation = create(:conversation)
message = create(:message, sender: create(:user), content: 'Hey [@John Peter](mention://user/1/john%20K) please check this?',
conversation: conversation)
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: conversation, secondary_actor: message)
expect(notification.push_message_body).to eq "#{message.sender.name}: Hey @John Peter please check this?"
end
it 'calls remove duplicate notification job' do