2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-16 16:53:41 +02:00
|
|
|
RSpec.describe AdministrateurMailer, type: :mailer do
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let(:admin_email) { 'administrateur@email.fr' }
|
2023-10-18 07:10:26 +02:00
|
|
|
|
2022-08-16 16:53:41 +02:00
|
|
|
describe '.notify_procedure_expires_when_termine_forced' do
|
|
|
|
subject { described_class.notify_procedure_expires_when_termine_forced(admin_email, procedure) }
|
2023-10-18 07:10:26 +02:00
|
|
|
|
2022-08-16 16:53:41 +02:00
|
|
|
it { expect(subject.to).to eq([admin_email]) }
|
|
|
|
it { expect(subject.subject).to include("La suppression automatique des dossiers a été activée sur la démarche") }
|
2023-10-18 07:10:26 +02:00
|
|
|
|
|
|
|
context 'when perform_later is called' do
|
|
|
|
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-08-16 16:53:41 +02:00
|
|
|
end
|
2023-10-18 07:10:26 +02:00
|
|
|
|
2023-01-23 14:56:05 +01:00
|
|
|
describe '.activate_before_expiration' do
|
|
|
|
let(:user) { create(:user, reset_password_sent_at: 2.days.ago) }
|
|
|
|
let(:token) { SecureRandom.hex }
|
2023-10-18 07:10:26 +02:00
|
|
|
subject { described_class.activate_before_expiration(user, token) }
|
2023-01-23 14:56:05 +01:00
|
|
|
|
|
|
|
context 'without SafeMailer configured' do
|
2024-05-29 12:24:05 +02:00
|
|
|
it do
|
|
|
|
expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil)
|
|
|
|
expect(subject['BYPASS_UNVERIFIED_MAIL_PROTECTION']).to be_present
|
|
|
|
end
|
2023-01-23 14:56:05 +01:00
|
|
|
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
|
2023-01-23 14:56:05 +01:00
|
|
|
end
|
2023-09-27 11:12:54 +02:00
|
|
|
|
|
|
|
describe '.notify_service_without_siret' do
|
|
|
|
subject { described_class.notify_service_without_siret(admin_email) }
|
2023-10-18 07:10:26 +02:00
|
|
|
|
2023-09-27 11:12:54 +02:00
|
|
|
it { expect(subject.to).to eq([admin_email]) }
|
|
|
|
it { expect(subject.subject).to eq("Siret manquant sur un de vos services") }
|
|
|
|
it { expect(subject.body).to include("un de vos services n'a pas son siret renseigné") }
|
2023-10-18 07:10:26 +02:00
|
|
|
|
|
|
|
context 'when perform_later is called' do
|
|
|
|
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
|
2023-09-27 11:12:54 +02:00
|
|
|
end
|
2022-08-16 16:53:41 +02:00
|
|
|
end
|