2019-07-09 17:08:27 +02:00
|
|
|
|
RSpec.describe UserMailer, type: :mailer do
|
2023-10-18 07:10:26 +02:00
|
|
|
|
let(:user) { create(:user) }
|
2019-07-09 17:08:27 +02:00
|
|
|
|
|
|
|
|
|
describe '.new_account_warning' do
|
|
|
|
|
subject { described_class.new_account_warning(user) }
|
|
|
|
|
|
|
|
|
|
it { expect(subject.to).to eq([user.email]) }
|
|
|
|
|
it { expect(subject.body).to include(user.email) }
|
2020-02-11 18:17:09 +01:00
|
|
|
|
it { expect(subject.body).to have_link('J’ai oublié mon mot de passe') }
|
|
|
|
|
|
|
|
|
|
context 'when a procedure is provided' do
|
|
|
|
|
let(:procedure) { build(:procedure) }
|
|
|
|
|
|
|
|
|
|
subject { described_class.new_account_warning(user, procedure) }
|
|
|
|
|
|
|
|
|
|
it { expect(subject.body).to have_link("Commencer la démarche « #{procedure.libelle} »", href: commencer_sign_in_url(path: procedure.path)) }
|
|
|
|
|
end
|
2023-01-23 14:56:05 +01:00
|
|
|
|
|
|
|
|
|
context 'without SafeMailer configured' do
|
|
|
|
|
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
expect { subject.deliver_later }.to have_enqueued_job.on_queue(Rails.application.config.action_mailer.deliver_later_queue_name)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-07-09 17:08:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
2021-10-26 13:36:14 +02:00
|
|
|
|
describe '.ask_for_merge' do
|
2019-07-09 17:08:27 +02:00
|
|
|
|
let(:requested_email) { 'new@exemple.fr' }
|
|
|
|
|
|
2021-10-26 13:36:14 +02:00
|
|
|
|
subject { described_class.ask_for_merge(user, requested_email) }
|
2019-07-09 17:08:27 +02:00
|
|
|
|
|
|
|
|
|
it { expect(subject.to).to eq([requested_email]) }
|
|
|
|
|
it { expect(subject.body).to include(requested_email) }
|
2023-01-23 14:56:05 +01:00
|
|
|
|
|
|
|
|
|
context 'without SafeMailer configured' do
|
|
|
|
|
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
expect { subject.deliver_later }.to have_enqueued_job.on_queue(Rails.application.config.action_mailer.deliver_later_queue_name)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-07-09 17:08:27 +02:00
|
|
|
|
end
|
2021-11-17 16:21:55 +01:00
|
|
|
|
|
|
|
|
|
describe '.france_connect_merge_confirmation' do
|
|
|
|
|
let(:email) { 'new.exemple.fr' }
|
|
|
|
|
let(:code) { '123456' }
|
|
|
|
|
|
2021-11-23 10:54:59 +01:00
|
|
|
|
subject { described_class.france_connect_merge_confirmation(email, code, 15.minutes.from_now) }
|
2021-11-17 16:21:55 +01:00
|
|
|
|
|
|
|
|
|
it { expect(subject.to).to eq([email]) }
|
|
|
|
|
it { expect(subject.body).to include(france_connect_particulier_mail_merge_with_existing_account_url(merge_token: code)) }
|
2023-01-23 14:56:05 +01:00
|
|
|
|
|
|
|
|
|
context 'without SafeMailer configured' do
|
|
|
|
|
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
expect { subject.deliver_later }.to have_enqueued_job.on_queue(Rails.application.config.action_mailer.deliver_later_queue_name)
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-11-17 16:21:55 +01:00
|
|
|
|
end
|
2022-06-23 13:51:58 +02:00
|
|
|
|
|
|
|
|
|
describe '.send_archive' do
|
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
|
let(:archive) { create(:archive) }
|
|
|
|
|
subject { described_class.send_archive(role, procedure, archive) }
|
|
|
|
|
|
|
|
|
|
context 'instructeur' do
|
|
|
|
|
let(:role) { create(:instructeur) }
|
|
|
|
|
it { expect(subject.to).to eq([role.user.email]) }
|
|
|
|
|
it { expect(subject.body).to have_link('Consulter mes archives', href: instructeur_archives_url(procedure)) }
|
|
|
|
|
it { expect(subject.body).to have_link("#{procedure.id} − #{procedure.libelle}", href: instructeur_procedure_url(procedure)) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'instructeur' do
|
|
|
|
|
let(:role) { create(:administrateur) }
|
|
|
|
|
it { expect(subject.to).to eq([role.user.email]) }
|
|
|
|
|
it { expect(subject.body).to have_link('Consulter mes archives', href: admin_procedure_archives_url(procedure)) }
|
|
|
|
|
it { expect(subject.body).to have_link("#{procedure.id} − #{procedure.libelle}", href: admin_procedure_url(procedure)) }
|
|
|
|
|
end
|
2023-10-18 07:10:26 +02:00
|
|
|
|
|
|
|
|
|
context 'when perform_later is called' do
|
|
|
|
|
let(:role) { create(:administrateur) }
|
|
|
|
|
let(:custom_queue) { 'low_priority' }
|
|
|
|
|
before { ENV['BULK_EMAIL_QUEUE'] = custom_queue }
|
|
|
|
|
it 'enqueues email is custom queue for low priority delivery' do
|
|
|
|
|
expect { subject.deliver_later }.to have_enqueued_job.on_queue(custom_queue)
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-06-23 13:51:58 +02:00
|
|
|
|
end
|
2019-07-09 17:08:27 +02:00
|
|
|
|
end
|