2023-02-21 19:55:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-18 17:38:14 -05:00
|
|
|
require 'rails_helper'
|
2016-03-19 14:20:07 -04:00
|
|
|
|
2023-05-03 23:49:53 -04:00
|
|
|
RSpec.describe NotificationMailer do
|
2023-08-01 13:34:40 -04:00
|
|
|
let(:receiver) { Fabricate(:user, account_attributes: { username: 'alice' }) }
|
2016-03-19 14:20:07 -04:00
|
|
|
let(:sender) { Fabricate(:account, username: 'bob') }
|
2017-06-11 06:04:35 -04: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') }
|
|
|
|
|
2023-02-18 17:38:14 -05:00
|
|
|
describe 'mention' do
|
2016-11-19 18:33:02 -05:00
|
|
|
let(:mention) { Mention.create!(account: receiver.account, status: foreign_status) }
|
2023-07-09 21:06:22 -04:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: mention) }
|
|
|
|
let(:mail) { prepared_mailer_for(receiver.account).mention }
|
2016-03-19 14:20:07 -04:00
|
|
|
|
2017-06-11 06:04:35 -04:00
|
|
|
include_examples 'localized subject', 'notification_mailer.mention.subject', name: 'bob'
|
2023-11-17 04:50:19 -05:00
|
|
|
|
|
|
|
it 'renders the email' do
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject('You were mentioned by bob'))
|
|
|
|
.and(have_body_text('You were mentioned by bob'))
|
|
|
|
.and(have_body_text('The body of the foreign status'))
|
2024-09-24 08:07:16 -04:00
|
|
|
.and have_thread_headers
|
|
|
|
.and have_standard_headers('mention').for(receiver)
|
2016-03-19 14:20:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-18 17:38:14 -05:00
|
|
|
describe 'follow' do
|
2016-11-19 18:33:02 -05:00
|
|
|
let(:follow) { sender.follow!(receiver.account) }
|
2023-07-09 21:06:22 -04:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: follow) }
|
|
|
|
let(:mail) { prepared_mailer_for(receiver.account).follow }
|
2016-03-19 14:20:07 -04:00
|
|
|
|
2017-06-11 06:04:35 -04:00
|
|
|
include_examples 'localized subject', 'notification_mailer.follow.subject', name: 'bob'
|
2016-03-19 14:20:07 -04:00
|
|
|
|
2023-11-17 04:50:19 -05:00
|
|
|
it 'renders the email' do
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject('bob is now following you'))
|
|
|
|
.and(have_body_text('bob is now following you'))
|
2024-09-24 08:07:16 -04:00
|
|
|
.and have_standard_headers('follow').for(receiver)
|
2016-03-19 14:20:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-18 17:38:14 -05:00
|
|
|
describe 'favourite' do
|
2016-11-19 18:33:02 -05:00
|
|
|
let(:favourite) { Favourite.create!(account: sender, status: own_status) }
|
2023-07-09 21:06:22 -04:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: favourite) }
|
|
|
|
let(:mail) { prepared_mailer_for(own_status.account).favourite }
|
2016-03-19 14:20:07 -04:00
|
|
|
|
2017-06-11 06:04:35 -04:00
|
|
|
include_examples 'localized subject', 'notification_mailer.favourite.subject', name: 'bob'
|
2023-11-17 04:50:19 -05:00
|
|
|
|
|
|
|
it 'renders the email' do
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject('bob favorited your post'))
|
|
|
|
.and(have_body_text('Your post was favorited by bob'))
|
|
|
|
.and(have_body_text('The body of the own status'))
|
2024-09-24 08:07:16 -04:00
|
|
|
.and have_thread_headers
|
|
|
|
.and have_standard_headers('favourite').for(receiver)
|
2016-03-19 14:20:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-18 17:38:14 -05:00
|
|
|
describe 'reblog' do
|
2016-11-19 18:33:02 -05:00
|
|
|
let(:reblog) { Status.create!(account: sender, reblog: own_status) }
|
2023-07-09 21:06:22 -04:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: reblog) }
|
|
|
|
let(:mail) { prepared_mailer_for(own_status.account).reblog }
|
2016-03-19 14:20:07 -04:00
|
|
|
|
2017-06-11 06:04:35 -04:00
|
|
|
include_examples 'localized subject', 'notification_mailer.reblog.subject', name: 'bob'
|
2023-11-17 04:50:19 -05:00
|
|
|
|
|
|
|
it 'renders the email' do
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject('bob boosted your post'))
|
|
|
|
.and(have_body_text('Your post was boosted by bob'))
|
|
|
|
.and(have_body_text('The body of the own status'))
|
2024-09-24 08:07:16 -04:00
|
|
|
.and have_thread_headers
|
|
|
|
.and have_standard_headers('reblog').for(receiver)
|
2016-03-19 14:20:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-05 14:56:00 -04:00
|
|
|
describe 'follow_request' do
|
|
|
|
let(:follow_request) { Fabricate(:follow_request, account: sender, target_account: receiver.account) }
|
2023-07-09 21:06:22 -04:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: follow_request) }
|
|
|
|
let(:mail) { prepared_mailer_for(receiver.account).follow_request }
|
2017-05-05 14:56:00 -04:00
|
|
|
|
2017-06-11 06:04:35 -04:00
|
|
|
include_examples 'localized subject', 'notification_mailer.follow_request.subject', name: 'bob'
|
2017-05-05 14:56:00 -04:00
|
|
|
|
2023-11-17 04:50:19 -05:00
|
|
|
it 'renders the email' do
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject('Pending follower: bob'))
|
|
|
|
.and(have_body_text('bob has requested to follow you'))
|
2024-09-24 08:07:16 -04:00
|
|
|
.and have_standard_headers('follow_request').for(receiver)
|
2017-05-05 14:56:00 -04:00
|
|
|
end
|
|
|
|
end
|
2023-07-09 21:06:22 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def prepared_mailer_for(recipient)
|
|
|
|
described_class.with(recipient: recipient, notification: notification)
|
|
|
|
end
|
2016-03-19 14:20:07 -04:00
|
|
|
end
|