2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
require 'rails_helper'
|
2016-03-20 05:20:07 +11:00
|
|
|
|
2023-05-04 13:49:53 +10:00
|
|
|
RSpec.describe NotificationMailer do
|
2023-08-02 03:34:40 +10:00
|
|
|
let(:receiver) { Fabricate(:user, account_attributes: { username: 'alice' }) }
|
2016-03-20 05:20:07 +11:00
|
|
|
let(:sender) { Fabricate(:account, username: 'bob') }
|
2017-06-11 20:04:35 +10: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-08-02 03:34:40 +10:00
|
|
|
shared_examples 'headers' do |type, thread|
|
|
|
|
it 'renders the to and from headers' do
|
|
|
|
expect(mail[:to].value).to eq "#{receiver.account.username} <#{receiver.email}>"
|
|
|
|
expect(mail.from).to eq ['notifications@localhost']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the list headers' do
|
|
|
|
expect(mail['List-ID'].value).to eq "<#{type}.alice.cb6e6126.ngrok.io>"
|
|
|
|
expect(mail['List-Unsubscribe'].value).to match(%r{<https://cb6e6126.ngrok.io/unsubscribe\?token=.+>})
|
|
|
|
expect(mail['List-Unsubscribe'].value).to match("&type=#{type}")
|
|
|
|
expect(mail['List-Unsubscribe-Post'].value).to eq 'List-Unsubscribe=One-Click'
|
|
|
|
end
|
|
|
|
|
|
|
|
if thread
|
|
|
|
it 'renders the thread headers' do
|
|
|
|
expect(mail['In-Reply-To'].value).to match(/<conversation-\d+.\d\d\d\d-\d\d-\d\d@cb6e6126.ngrok.io>/)
|
|
|
|
expect(mail['References'].value).to match(/<conversation-\d+.\d\d\d\d-\d\d-\d\d@cb6e6126.ngrok.io>/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
describe 'mention' do
|
2016-11-20 10:33:02 +11:00
|
|
|
let(:mention) { Mention.create!(account: receiver.account, status: foreign_status) }
|
2023-07-10 11:06:22 +10:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: mention) }
|
|
|
|
let(:mail) { prepared_mailer_for(receiver.account).mention }
|
2016-03-20 05:20:07 +11:00
|
|
|
|
2017-06-11 20:04:35 +10:00
|
|
|
include_examples 'localized subject', 'notification_mailer.mention.subject', name: 'bob'
|
2023-08-02 03:34:40 +10:00
|
|
|
include_examples 'headers', 'mention', true
|
2017-06-11 20:04:35 +10:00
|
|
|
|
2023-08-02 03:34:40 +10:00
|
|
|
it 'renders the subject' do
|
2023-02-19 09:38:14 +11:00
|
|
|
expect(mail.subject).to eq('You were mentioned by bob')
|
2016-03-20 05:20:07 +11:00
|
|
|
end
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'renders the body' do
|
|
|
|
expect(mail.body.encoded).to match('You were mentioned by bob')
|
2017-06-11 20:04:35 +10:00
|
|
|
expect(mail.body.encoded).to include 'The body of the foreign status'
|
2016-03-20 05:20:07 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
describe 'follow' do
|
2016-11-20 10:33:02 +11:00
|
|
|
let(:follow) { sender.follow!(receiver.account) }
|
2023-07-10 11:06:22 +10:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: follow) }
|
|
|
|
let(:mail) { prepared_mailer_for(receiver.account).follow }
|
2016-03-20 05:20:07 +11:00
|
|
|
|
2017-06-11 20:04:35 +10:00
|
|
|
include_examples 'localized subject', 'notification_mailer.follow.subject', name: 'bob'
|
2023-08-02 03:34:40 +10:00
|
|
|
include_examples 'headers', 'follow', false
|
2017-06-11 20:04:35 +10:00
|
|
|
|
2023-08-02 03:34:40 +10:00
|
|
|
it 'renders the subject' do
|
2023-02-19 09:38:14 +11:00
|
|
|
expect(mail.subject).to eq('bob is now following you')
|
2016-03-20 05:20:07 +11:00
|
|
|
end
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'renders the body' do
|
|
|
|
expect(mail.body.encoded).to match('bob is now following you')
|
2016-03-20 05:20:07 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
describe 'favourite' do
|
2016-11-20 10:33:02 +11:00
|
|
|
let(:favourite) { Favourite.create!(account: sender, status: own_status) }
|
2023-07-10 11:06:22 +10:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: favourite) }
|
|
|
|
let(:mail) { prepared_mailer_for(own_status.account).favourite }
|
2016-03-20 05:20:07 +11:00
|
|
|
|
2017-06-11 20:04:35 +10:00
|
|
|
include_examples 'localized subject', 'notification_mailer.favourite.subject', name: 'bob'
|
2023-08-02 03:34:40 +10:00
|
|
|
include_examples 'headers', 'favourite', true
|
2017-06-11 20:04:35 +10:00
|
|
|
|
2023-08-02 03:34:40 +10:00
|
|
|
it 'renders the subject' do
|
2023-04-30 17:33:37 +10:00
|
|
|
expect(mail.subject).to eq('bob favorited your post')
|
2016-03-20 05:20:07 +11:00
|
|
|
end
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'renders the body' do
|
2023-04-30 17:33:37 +10:00
|
|
|
expect(mail.body.encoded).to match('Your post was favorited by bob')
|
2017-06-11 20:04:35 +10:00
|
|
|
expect(mail.body.encoded).to include 'The body of the own status'
|
2016-03-20 05:20:07 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
describe 'reblog' do
|
2016-11-20 10:33:02 +11:00
|
|
|
let(:reblog) { Status.create!(account: sender, reblog: own_status) }
|
2023-07-10 11:06:22 +10:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: reblog) }
|
|
|
|
let(:mail) { prepared_mailer_for(own_status.account).reblog }
|
2016-03-20 05:20:07 +11:00
|
|
|
|
2017-06-11 20:04:35 +10:00
|
|
|
include_examples 'localized subject', 'notification_mailer.reblog.subject', name: 'bob'
|
2023-08-02 03:34:40 +10:00
|
|
|
include_examples 'headers', 'reblog', true
|
2017-06-11 20:04:35 +10:00
|
|
|
|
2023-08-02 03:34:40 +10:00
|
|
|
it 'renders the subject' do
|
2023-02-19 09:38:14 +11:00
|
|
|
expect(mail.subject).to eq('bob boosted your post')
|
2016-03-20 05:20:07 +11:00
|
|
|
end
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'renders the body' do
|
|
|
|
expect(mail.body.encoded).to match('Your post was boosted by bob')
|
2017-06-11 20:04:35 +10:00
|
|
|
expect(mail.body.encoded).to include 'The body of the own status'
|
2016-03-20 05:20:07 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-06 04:56:00 +10:00
|
|
|
describe 'follow_request' do
|
|
|
|
let(:follow_request) { Fabricate(:follow_request, account: sender, target_account: receiver.account) }
|
2023-07-10 11:06:22 +10:00
|
|
|
let(:notification) { Notification.create!(account: receiver.account, activity: follow_request) }
|
|
|
|
let(:mail) { prepared_mailer_for(receiver.account).follow_request }
|
2017-05-06 04:56:00 +10:00
|
|
|
|
2017-06-11 20:04:35 +10:00
|
|
|
include_examples 'localized subject', 'notification_mailer.follow_request.subject', name: 'bob'
|
2023-08-02 03:34:40 +10:00
|
|
|
include_examples 'headers', 'follow_request', false
|
2017-06-11 20:04:35 +10:00
|
|
|
|
2023-08-02 03:34:40 +10:00
|
|
|
it 'renders the subject' do
|
2017-05-06 04:56:00 +10:00
|
|
|
expect(mail.subject).to eq('Pending follower: bob')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the body' do
|
2023-02-19 09:38:14 +11:00
|
|
|
expect(mail.body.encoded).to match('bob has requested to follow you')
|
2017-05-06 04:56:00 +10:00
|
|
|
end
|
|
|
|
end
|
2023-07-10 11:06:22 +10:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def prepared_mailer_for(recipient)
|
|
|
|
described_class.with(recipient: recipient, notification: notification)
|
|
|
|
end
|
2016-03-20 05:20:07 +11:00
|
|
|
end
|