2023-01-11 09:44:39 +01:00
|
|
|
RSpec.describe DeviseUserMailer, type: :mailer do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:token) { SecureRandom.hex }
|
|
|
|
describe '.confirmation_instructions' do
|
2023-10-18 07:10:26 +02:00
|
|
|
subject { described_class.confirmation_instructions(user, token, opts = {}) }
|
|
|
|
|
2023-01-11 09:44:39 +01:00
|
|
|
context 'without SafeMailer configured' do
|
2024-05-29 09:52:54 +02:00
|
|
|
it do
|
|
|
|
expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil)
|
|
|
|
expect(subject[BalancerDeliveryMethod::BYPASS_UNVERIFIED_MAIL_PROTECTION]).to be_present
|
|
|
|
end
|
2023-01-11 09:44:39 +01:00
|
|
|
end
|
2023-10-18 07:10:26 +02:00
|
|
|
|
2023-01-11 09:44:39 +01:00
|
|
|
context 'with SafeMailer configured' do
|
|
|
|
let(:forced_delivery_method) { :kikoo }
|
|
|
|
before { allow(SafeMailer).to receive(:forced_delivery_method).and_return(forced_delivery_method) }
|
|
|
|
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) }
|
|
|
|
end
|
2023-10-18 07:10:26 +02:00
|
|
|
|
|
|
|
context 'when perform_later is called' do
|
|
|
|
it 'enqueues email in default queue for high priority delivery' do
|
2024-03-25 19:13:09 +01:00
|
|
|
expect { subject.deliver_later }.to have_enqueued_job.on_queue(Rails.application.config.action_mailer.deliver_later_queue_name)
|
|
|
|
end
|
2023-10-18 07:10:26 +02:00
|
|
|
end
|
2024-03-28 12:30:31 +01:00
|
|
|
|
|
|
|
describe "i18n" do
|
|
|
|
context "when locale is fr" do
|
|
|
|
let(:user) { create(:user, locale: :fr) }
|
|
|
|
|
|
|
|
it "uses fr locale" do
|
|
|
|
expect(subject.body).to include("Activez votre compte")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when locale is en" do
|
|
|
|
let(:user) { create(:user, locale: :en) }
|
|
|
|
|
|
|
|
it "uses en locale" do
|
|
|
|
expect(subject.body).to include("Activate account")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-01-11 09:44:39 +01:00
|
|
|
end
|
2024-03-25 19:13:09 +01:00
|
|
|
|
|
|
|
describe 'headers for user' do
|
|
|
|
context "confirmation email" do
|
|
|
|
subject { described_class.confirmation_instructions(user, token, opts = {}) }
|
|
|
|
|
|
|
|
context "legacy domain" do
|
|
|
|
it "respect preferred domain" do
|
|
|
|
expect(header_value("From", subject.message)).to eq(NO_REPLY_EMAIL)
|
|
|
|
expect(header_value("Reply-To", subject.message)).to eq(NO_REPLY_EMAIL)
|
|
|
|
expect(subject.message.to_s).to include("#{ENV.fetch("APP_HOST_LEGACY")}/users/confirmation")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "new domain" do
|
|
|
|
let(:user) { create(:user, preferred_domain: :demarches_gouv_fr) }
|
|
|
|
|
|
|
|
it "respect preferred domain" do
|
|
|
|
expect(header_value("From", subject.message)).to eq("Ne pas répondre <ne-pas-repondre@demarches.gouv.fr>")
|
|
|
|
expect(header_value("Reply-To", subject.message)).to eq("Ne pas répondre <ne-pas-repondre@demarches.gouv.fr>")
|
2024-04-18 18:16:22 +02:00
|
|
|
expect(subject.message.to_s).to include("demarches.gouv.fr/users/confirmation")
|
|
|
|
expect(subject.message.to_s).to include("//demarches.gouv.fr/assets/mailer/republique")
|
2024-03-25 19:13:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-03-25 20:12:12 +01:00
|
|
|
|
|
|
|
context "reset password instructions" do
|
|
|
|
subject { described_class.reset_password_instructions(user, token) }
|
|
|
|
|
|
|
|
context "legacy domain" do
|
|
|
|
it "respect preferred domain" do
|
|
|
|
expect(header_value("From", subject.message)).to include(CONTACT_EMAIL)
|
|
|
|
expect(subject.message.to_s).to include("#{ENV.fetch("APP_HOST_LEGACY")}/users/password")
|
2024-05-31 14:33:40 +02:00
|
|
|
expect(subject[BalancerDeliveryMethod::BYPASS_UNVERIFIED_MAIL_PROTECTION]).to be_present
|
2024-03-25 20:12:12 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "new domain" do
|
|
|
|
let(:user) { create(:user, preferred_domain: :demarches_gouv_fr) }
|
|
|
|
|
|
|
|
it "respect preferred domain" do
|
|
|
|
expect(header_value("From", subject.message)).to include("@demarches.gouv.fr")
|
2024-04-18 18:16:22 +02:00
|
|
|
expect(subject.message.to_s).to include("demarches.gouv.fr/users/password")
|
2024-03-25 20:12:12 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-03-25 19:13:09 +01:00
|
|
|
end
|
2023-01-11 09:44:39 +01:00
|
|
|
end
|