feat(mail): devise confirmation instructions respect user preferred host

This commit is contained in:
Colin Darie 2024-03-25 19:13:09 +01:00
parent 863784a1a9
commit d14fe83261
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
4 changed files with 70 additions and 6 deletions

View file

@ -16,8 +16,37 @@ RSpec.describe DeviseUserMailer, type: :mailer do
context 'when perform_later is called' do
it 'enqueues email in default queue for high priority delivery' do
expect { subject.deliver_later }.to have_enqueued_job.on_queue(Rails.application.config.action_mailer.deliver_later_queue_name)
end
expect { subject.deliver_later }.to have_enqueued_job.on_queue(Rails.application.config.action_mailer.deliver_later_queue_name)
end
end
end
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>")
expect(subject.message.to_s).to include("#{ENV.fetch("APP_HOST")}/users/confirmation")
expect(subject.message.to_s).to include("//#{ENV.fetch("APP_HOST")}/assets/mailer/republique")
end
end
end
end
def header_value(name, message)
message.header.fields.find { _1.name == name }.value
end
end