2016-03-19 18:20:07 +00:00
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
RSpec.describe NotificationMailer, type: :mailer do
|
|
|
|
let(:receiver) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
|
|
|
let(:sender) { Fabricate(:account, username: 'bob') }
|
2017-06-11 10:04:35 +00:00
|
|
|
let(:foreign_status) { Fabricate(:status, account: sender, text: 'The body of the foreign status') }
|
|
|
|
let(:own_status) { Fabricate(:status, account: receiver.account, text: 'The body of the own status') }
|
|
|
|
|
|
|
|
shared_examples 'localized subject' do |*args, **kwrest|
|
|
|
|
it 'renders subject localized for the locale of the receiver' do
|
2018-02-17 13:27:51 +00:00
|
|
|
locale = %i(de en).sample
|
2017-06-11 10:04:35 +00:00
|
|
|
receiver.update!(locale: locale)
|
2021-05-06 12:22:54 +00:00
|
|
|
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: locale))
|
2017-06-11 10:04:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders subject localized for the default locale if the locale of the receiver is unavailable' do
|
|
|
|
receiver.update!(locale: nil)
|
2021-05-06 12:22:54 +00:00
|
|
|
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: I18n.default_locale))
|
2017-06-11 10:04:35 +00:00
|
|
|
end
|
|
|
|
end
|
2016-03-19 18:20:07 +00:00
|
|
|
|
|
|
|
describe "mention" do
|
2016-11-19 23:33:02 +00:00
|
|
|
let(:mention) { Mention.create!(account: receiver.account, status: foreign_status) }
|
|
|
|
let(:mail) { NotificationMailer.mention(receiver.account, Notification.create!(account: receiver.account, activity: mention)) }
|
2016-03-19 18:20:07 +00:00
|
|
|
|
2017-06-11 10:04:35 +00:00
|
|
|
include_examples 'localized subject', 'notification_mailer.mention.subject', name: 'bob'
|
|
|
|
|
2016-03-19 18:20:07 +00:00
|
|
|
it "renders the headers" do
|
|
|
|
expect(mail.subject).to eq("You were mentioned by bob")
|
|
|
|
expect(mail.to).to eq([receiver.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the body" do
|
|
|
|
expect(mail.body.encoded).to match("You were mentioned by bob")
|
2017-06-11 10:04:35 +00:00
|
|
|
expect(mail.body.encoded).to include 'The body of the foreign status'
|
2016-03-19 18:20:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "follow" do
|
2016-11-19 23:33:02 +00:00
|
|
|
let(:follow) { sender.follow!(receiver.account) }
|
|
|
|
let(:mail) { NotificationMailer.follow(receiver.account, Notification.create!(account: receiver.account, activity: follow)) }
|
2016-03-19 18:20:07 +00:00
|
|
|
|
2017-06-11 10:04:35 +00:00
|
|
|
include_examples 'localized subject', 'notification_mailer.follow.subject', name: 'bob'
|
|
|
|
|
2016-03-19 18:20:07 +00:00
|
|
|
it "renders the headers" do
|
|
|
|
expect(mail.subject).to eq("bob is now following you")
|
|
|
|
expect(mail.to).to eq([receiver.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the body" do
|
|
|
|
expect(mail.body.encoded).to match("bob is now following you")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "favourite" do
|
2016-11-19 23:33:02 +00:00
|
|
|
let(:favourite) { Favourite.create!(account: sender, status: own_status) }
|
|
|
|
let(:mail) { NotificationMailer.favourite(own_status.account, Notification.create!(account: receiver.account, activity: favourite)) }
|
2016-03-19 18:20:07 +00:00
|
|
|
|
2017-06-11 10:04:35 +00:00
|
|
|
include_examples 'localized subject', 'notification_mailer.favourite.subject', name: 'bob'
|
|
|
|
|
2016-03-19 18:20:07 +00:00
|
|
|
it "renders the headers" do
|
2021-04-21 16:31:24 +00:00
|
|
|
expect(mail.subject).to eq("bob favourited your post")
|
2016-03-19 18:20:07 +00:00
|
|
|
expect(mail.to).to eq([receiver.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the body" do
|
2021-04-21 16:31:24 +00:00
|
|
|
expect(mail.body.encoded).to match("Your post was favourited by bob")
|
2017-06-11 10:04:35 +00:00
|
|
|
expect(mail.body.encoded).to include 'The body of the own status'
|
2016-03-19 18:20:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "reblog" do
|
2016-11-19 23:33:02 +00:00
|
|
|
let(:reblog) { Status.create!(account: sender, reblog: own_status) }
|
|
|
|
let(:mail) { NotificationMailer.reblog(own_status.account, Notification.create!(account: receiver.account, activity: reblog)) }
|
2016-03-19 18:20:07 +00:00
|
|
|
|
2017-06-11 10:04:35 +00:00
|
|
|
include_examples 'localized subject', 'notification_mailer.reblog.subject', name: 'bob'
|
|
|
|
|
2016-03-19 18:20:07 +00:00
|
|
|
it "renders the headers" do
|
2021-04-21 16:31:24 +00:00
|
|
|
expect(mail.subject).to eq("bob boosted your post")
|
2016-03-19 18:20:07 +00:00
|
|
|
expect(mail.to).to eq([receiver.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the body" do
|
2021-04-21 16:31:24 +00:00
|
|
|
expect(mail.body.encoded).to match("Your post was boosted by bob")
|
2017-06-11 10:04:35 +00:00
|
|
|
expect(mail.body.encoded).to include 'The body of the own status'
|
2016-03-19 18:20:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-05 18:56:00 +00:00
|
|
|
describe 'follow_request' do
|
|
|
|
let(:follow_request) { Fabricate(:follow_request, account: sender, target_account: receiver.account) }
|
|
|
|
let(:mail) { NotificationMailer.follow_request(receiver.account, Notification.create!(account: receiver.account, activity: follow_request)) }
|
|
|
|
|
2017-06-11 10:04:35 +00:00
|
|
|
include_examples 'localized subject', 'notification_mailer.follow_request.subject', name: 'bob'
|
|
|
|
|
2017-05-05 18:56:00 +00:00
|
|
|
it 'renders the headers' do
|
|
|
|
expect(mail.subject).to eq('Pending follower: bob')
|
|
|
|
expect(mail.to).to eq([receiver.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the body' do
|
|
|
|
expect(mail.body.encoded).to match("bob has requested to follow you")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-20 07:10:27 +00:00
|
|
|
describe "emoji_reaction" do
|
|
|
|
let(:emoji_reaction) { EmojiReaction.create!(account: sender, status: own_status, name: '😂', custom_emoji: nil) }
|
|
|
|
let(:mail) { NotificationMailer.emoji_reaction(own_status.account, Notification.create!(account: receiver.account, activity: emoji_reaction)) }
|
|
|
|
|
|
|
|
include_examples 'localized subject', 'notification_mailer.emoji_reaction.subject', name: 'bob'
|
|
|
|
|
|
|
|
it "renders the headers" do
|
|
|
|
expect(mail.subject).to eq("bob emoji reactioned your post")
|
|
|
|
expect(mail.to).to eq([receiver.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the body" do
|
|
|
|
expect(mail.body.encoded).to match("Your post was emoji reactioned by bob")
|
|
|
|
expect(mail.body.encoded).to include 'The body of the own status'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-20 07:11:06 +00:00
|
|
|
describe "status_reference" do
|
|
|
|
let(:status_reference) { StatusReference.create!(status: foreign_status, target_status: own_status) }
|
|
|
|
let(:mail) { NotificationMailer.status_reference(own_status.account, Notification.create!(account: receiver.account, activity: status_reference)) }
|
|
|
|
|
|
|
|
include_examples 'localized subject', 'notification_mailer.status_reference.subject', name: 'bob'
|
|
|
|
|
|
|
|
it "renders the headers" do
|
|
|
|
expect(mail.subject).to eq("bob referenced your post")
|
|
|
|
expect(mail.to).to eq([receiver.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the body" do
|
|
|
|
expect(mail.body.encoded).to match("Your post was referenced by bob")
|
|
|
|
expect(mail.body.encoded).to include 'The body of the foreign status'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-05 18:56:00 +00:00
|
|
|
describe 'digest' do
|
|
|
|
before do
|
2017-06-11 10:04:35 +00:00
|
|
|
mention = Fabricate(:mention, account: receiver.account, status: foreign_status)
|
2017-05-05 18:56:00 +00:00
|
|
|
Fabricate(:notification, account: receiver.account, activity: mention)
|
2017-06-11 10:04:35 +00:00
|
|
|
sender.follow!(receiver.account)
|
2017-05-05 18:56:00 +00:00
|
|
|
end
|
|
|
|
|
2017-06-11 10:04:35 +00:00
|
|
|
context do
|
|
|
|
let!(:mail) { NotificationMailer.digest(receiver.account, since: 5.days.ago) }
|
|
|
|
|
|
|
|
include_examples 'localized subject', 'notification_mailer.digest.subject', count: 1, name: 'bob'
|
|
|
|
|
|
|
|
it 'renders the headers' do
|
|
|
|
expect(mail.subject).to match('notification since your last')
|
|
|
|
expect(mail.to).to eq([receiver.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the body' do
|
|
|
|
expect(mail.body.encoded).to match('brief summary')
|
|
|
|
expect(mail.body.encoded).to include 'The body of the foreign status'
|
|
|
|
expect(mail.body.encoded).to include sender.username
|
|
|
|
end
|
2017-05-05 18:56:00 +00:00
|
|
|
end
|
|
|
|
|
2019-01-02 09:47:32 +00:00
|
|
|
it 'includes activities since the receiver last signed in' do
|
2017-06-11 10:04:35 +00:00
|
|
|
receiver.update!(last_emailed_at: nil, current_sign_in_at: '2000-03-01T00:00:00Z')
|
|
|
|
mail = NotificationMailer.digest(receiver.account)
|
|
|
|
expect(mail.body.encoded).to include 'Mar 01, 2000, 00:00'
|
2017-05-05 18:56:00 +00:00
|
|
|
end
|
|
|
|
end
|
2016-03-19 18:20:07 +00:00
|
|
|
end
|