2017-06-17 01:15:00 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe UserMailer do
|
2017-06-17 01:15:00 +02:00
|
|
|
let(:receiver) { Fabricate(:user) }
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#confirmation_instructions' do
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.confirmation_instructions(receiver, 'spec') }
|
2017-06-17 01:15:00 +02:00
|
|
|
|
|
|
|
it 'renders confirmation instructions' do
|
|
|
|
receiver.update!(locale: nil)
|
2023-11-17 10:50:19 +01:00
|
|
|
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.confirmation_instructions.title')))
|
|
|
|
.and(have_body_text('spec'))
|
|
|
|
.and(have_body_text(Rails.configuration.x.local_domain))
|
2017-06-17 01:15:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'localized subject',
|
|
|
|
'devise.mailer.confirmation_instructions.subject',
|
|
|
|
instance: Rails.configuration.x.local_domain
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#reconfirmation_instructions' do
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.confirmation_instructions(receiver, 'spec') }
|
2018-01-02 16:55:00 +01:00
|
|
|
|
|
|
|
it 'renders reconfirmation instructions' do
|
|
|
|
receiver.update!(email: 'new-email@example.com', locale: nil)
|
2023-11-17 10:50:19 +01:00
|
|
|
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.reconfirmation_instructions.title')))
|
|
|
|
.and(have_body_text('spec'))
|
|
|
|
.and(have_body_text(Rails.configuration.x.local_domain))
|
2018-01-02 16:55:00 +01:00
|
|
|
end
|
2023-11-17 10:50:19 +01:00
|
|
|
|
|
|
|
include_examples 'localized subject',
|
|
|
|
'devise.mailer.confirmation_instructions.subject',
|
|
|
|
instance: Rails.configuration.x.local_domain
|
2018-01-02 16:55:00 +01:00
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#reset_password_instructions' do
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.reset_password_instructions(receiver, 'spec') }
|
2017-06-17 01:15:00 +02:00
|
|
|
|
|
|
|
it 'renders reset password instructions' do
|
|
|
|
receiver.update!(locale: nil)
|
2023-11-17 10:50:19 +01:00
|
|
|
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.reset_password_instructions.title')))
|
|
|
|
.and(have_body_text('spec'))
|
2017-06-17 01:15:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'localized subject',
|
|
|
|
'devise.mailer.reset_password_instructions.subject'
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#password_change' do
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.password_change(receiver) }
|
2017-06-17 01:15:00 +02:00
|
|
|
|
|
|
|
it 'renders password change notification' do
|
|
|
|
receiver.update!(locale: nil)
|
2023-11-17 10:50:19 +01:00
|
|
|
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.password_change.title')))
|
2017-06-17 01:15:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'localized subject',
|
|
|
|
'devise.mailer.password_change.subject'
|
|
|
|
end
|
2018-01-02 16:55:00 +01:00
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#email_changed' do
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.email_changed(receiver) }
|
2018-01-02 16:55:00 +01:00
|
|
|
|
|
|
|
it 'renders email change notification' do
|
|
|
|
receiver.update!(locale: nil)
|
2023-11-17 10:50:19 +01:00
|
|
|
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.email_changed.title')))
|
2018-01-02 16:55:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'localized subject',
|
|
|
|
'devise.mailer.email_changed.subject'
|
|
|
|
end
|
2022-04-07 14:47:30 +02:00
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#warning' do
|
2022-04-07 14:47:30 +02:00
|
|
|
let(:strike) { Fabricate(:account_warning, target_account: receiver.account, text: 'dont worry its just the testsuite', action: 'suspend') }
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.warning(receiver, strike) }
|
2022-04-07 14:47:30 +02:00
|
|
|
|
|
|
|
it 'renders warning notification' do
|
|
|
|
receiver.update!(locale: nil)
|
2023-11-17 10:50:19 +01:00
|
|
|
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_body_text(I18n.t('user_mailer.warning.title.suspend', acct: receiver.account.acct)))
|
|
|
|
.and(have_body_text(strike.text))
|
2022-04-07 14:47:30 +02:00
|
|
|
end
|
|
|
|
end
|
2023-03-04 17:16:11 +01:00
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#webauthn_credential_deleted' do
|
2023-03-04 17:16:11 +01:00
|
|
|
let(:credential) { Fabricate(:webauthn_credential, user_id: receiver.id) }
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.webauthn_credential_deleted(receiver, credential) }
|
2023-03-04 17:16:11 +01:00
|
|
|
|
|
|
|
it 'renders webauthn credential deleted notification' do
|
|
|
|
receiver.update!(locale: nil)
|
2023-11-17 10:50:19 +01:00
|
|
|
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.webauthn_credential.deleted.title')))
|
2023-03-04 17:16:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'localized subject',
|
|
|
|
'devise.mailer.webauthn_credential.deleted.subject'
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#suspicious_sign_in' do
|
2023-03-04 17:16:11 +01:00
|
|
|
let(:ip) { '192.168.0.1' }
|
|
|
|
let(:agent) { 'NCSA_Mosaic/2.0 (Windows 3.1)' }
|
|
|
|
let(:timestamp) { Time.now.utc }
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.suspicious_sign_in(receiver, ip, agent, timestamp) }
|
2023-03-04 17:16:11 +01:00
|
|
|
|
|
|
|
it 'renders suspicious sign in notification' do
|
|
|
|
receiver.update!(locale: nil)
|
2023-11-17 10:50:19 +01:00
|
|
|
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_body_text(I18n.t('user_mailer.suspicious_sign_in.explanation')))
|
2023-03-04 17:16:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'localized subject',
|
|
|
|
'user_mailer.suspicious_sign_in.subject'
|
|
|
|
end
|
|
|
|
|
2024-01-22 14:55:43 +01:00
|
|
|
describe '#failed_2fa' do
|
|
|
|
let(:ip) { '192.168.0.1' }
|
|
|
|
let(:agent) { 'NCSA_Mosaic/2.0 (Windows 3.1)' }
|
|
|
|
let(:timestamp) { Time.now.utc }
|
|
|
|
let(:mail) { described_class.failed_2fa(receiver, ip, agent, timestamp) }
|
|
|
|
|
|
|
|
it 'renders failed 2FA notification' do
|
|
|
|
receiver.update!(locale: nil)
|
|
|
|
|
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_body_text(I18n.t('user_mailer.failed_2fa.explanation')))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'localized subject',
|
|
|
|
'user_mailer.failed_2fa.subject'
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#appeal_approved' do
|
2023-03-04 17:16:11 +01:00
|
|
|
let(:appeal) { Fabricate(:appeal, account: receiver.account, approved_at: Time.now.utc) }
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.appeal_approved(receiver, appeal) }
|
2023-03-04 17:16:11 +01:00
|
|
|
|
|
|
|
it 'renders appeal_approved notification' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at))))
|
|
|
|
.and(have_body_text(I18n.t('user_mailer.appeal_approved.title')))
|
2023-03-04 17:16:11 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#appeal_rejected' do
|
2023-03-04 17:16:11 +01:00
|
|
|
let(:appeal) { Fabricate(:appeal, account: receiver.account, rejected_at: Time.now.utc) }
|
2023-06-06 13:58:33 +02:00
|
|
|
let(:mail) { described_class.appeal_rejected(receiver, appeal) }
|
2023-03-04 17:16:11 +01:00
|
|
|
|
|
|
|
it 'renders appeal_rejected notification' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at))))
|
|
|
|
.and(have_body_text(I18n.t('user_mailer.appeal_rejected.title')))
|
2023-03-04 17:16:11 +01:00
|
|
|
end
|
|
|
|
end
|
2023-06-19 09:50:35 +02:00
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#two_factor_enabled' do
|
2023-06-19 09:50:35 +02:00
|
|
|
let(:mail) { described_class.two_factor_enabled(receiver) }
|
|
|
|
|
|
|
|
it 'renders two_factor_enabled mail' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('devise.mailer.two_factor_enabled.subject')))
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.two_factor_enabled.explanation')))
|
2023-06-19 09:50:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#two_factor_disabled' do
|
2023-06-19 09:50:35 +02:00
|
|
|
let(:mail) { described_class.two_factor_disabled(receiver) }
|
|
|
|
|
|
|
|
it 'renders two_factor_disabled mail' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('devise.mailer.two_factor_disabled.subject')))
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.two_factor_disabled.explanation')))
|
2023-06-19 09:50:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#webauthn_enabled' do
|
2023-06-19 09:50:35 +02:00
|
|
|
let(:mail) { described_class.webauthn_enabled(receiver) }
|
|
|
|
|
|
|
|
it 'renders webauthn_enabled mail' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('devise.mailer.webauthn_enabled.subject')))
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.webauthn_enabled.explanation')))
|
2023-06-19 09:50:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#webauthn_disabled' do
|
2023-06-19 09:50:35 +02:00
|
|
|
let(:mail) { described_class.webauthn_disabled(receiver) }
|
|
|
|
|
|
|
|
it 'renders webauthn_disabled mail' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('devise.mailer.webauthn_disabled.subject')))
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.webauthn_disabled.explanation')))
|
2023-06-19 09:50:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#two_factor_recovery_codes_changed' do
|
2023-06-19 09:50:35 +02:00
|
|
|
let(:mail) { described_class.two_factor_recovery_codes_changed(receiver) }
|
|
|
|
|
|
|
|
it 'renders two_factor_recovery_codes_changed mail' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('devise.mailer.two_factor_recovery_codes_changed.subject')))
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.two_factor_recovery_codes_changed.explanation')))
|
2023-06-19 09:50:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
describe '#webauthn_credential_added' do
|
2023-06-19 09:50:35 +02:00
|
|
|
let(:credential) { Fabricate.build(:webauthn_credential) }
|
|
|
|
let(:mail) { described_class.webauthn_credential_added(receiver, credential) }
|
|
|
|
|
|
|
|
it 'renders webauthn_credential_added mail' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('devise.mailer.webauthn_credential.added.subject')))
|
|
|
|
.and(have_body_text(I18n.t('devise.mailer.webauthn_credential.added.explanation')))
|
2023-06-19 09:50:35 +02:00
|
|
|
end
|
|
|
|
end
|
2023-10-27 11:57:16 +02:00
|
|
|
|
|
|
|
describe '#welcome' do
|
|
|
|
let(:mail) { described_class.welcome(receiver) }
|
|
|
|
|
2024-04-05 09:48:07 +02:00
|
|
|
before do
|
|
|
|
# This is a bit hacky and low-level but this allows stubbing trending tags
|
|
|
|
tag_ids = Fabricate.times(5, :tag).pluck(:id)
|
|
|
|
allow(Trends.tags).to receive(:query).and_return(instance_double(Trends::Query, allowed: Tag.where(id: tag_ids)))
|
|
|
|
end
|
|
|
|
|
2023-10-27 11:57:16 +02:00
|
|
|
it 'renders welcome mail' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('user_mailer.welcome.subject')))
|
|
|
|
.and(have_body_text(I18n.t('user_mailer.welcome.explanation')))
|
2023-10-27 11:57:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#backup_ready' do
|
|
|
|
let(:backup) { Fabricate(:backup) }
|
|
|
|
let(:mail) { described_class.backup_ready(receiver, backup) }
|
|
|
|
|
|
|
|
it 'renders backup_ready mail' do
|
2023-11-17 10:50:19 +01:00
|
|
|
expect(mail)
|
|
|
|
.to be_present
|
|
|
|
.and(have_subject(I18n.t('user_mailer.backup_ready.subject')))
|
|
|
|
.and(have_body_text(I18n.t('user_mailer.backup_ready.explanation')))
|
2023-10-27 11:57:16 +02:00
|
|
|
end
|
|
|
|
end
|
2017-06-17 01:15:00 +02:00
|
|
|
end
|