User correct username in mobile mention notifications (#15861)

This commit is contained in:
Josh Puetz 2021-12-22 10:31:22 -06:00 committed by GitHub
parent c75dd69d09
commit 10c13078cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -42,7 +42,7 @@ module Notifications
title: "🗣️ New Mention",
body: "#{I18n.t(
message_key,
user: mention.user.username,
user: mention.mentionable.user.username,
title: mentionable_title, # For an article this should be title, for comment should be article's title
)}:\n" \
"#{strip_tags(mention.mentionable.processed_html).strip}",

View file

@ -26,6 +26,7 @@ end
RSpec.describe Notifications::NewMention::Send, type: :service do
let(:user) { create(:user) }
let!(:article) { create(:article) }
let(:article_author) { article.user }
let!(:mention) { create(:mention, mentionable: article, user: user) }
it "creates users notifications" do
@ -47,6 +48,18 @@ RSpec.describe Notifications::NewMention::Send, type: :service do
expect(notification.json_data["user"]["username"]).to eq(article.user.username)
end
it "creates a mobile notification with name of the mentionable author" do
user.notification_setting.update(mobile_mention_notifications: true)
allow(PushNotifications::Send).to receive(:call)
allow(I18n).to receive(:t).with("views.notifications.mention.article_mobile",
user: mention.mentionable.user.username,
title: anything).and_call_original
described_class.call(mention)
expect(PushNotifications::Send).to have_received(:call)
expect(I18n).to have_received(:t)
end
it "does not send if the article has negative score already" do
prior_notification_size = Notification.all.size
article.update_column(:score, -1)