2019-08-06 11:02:54 +02:00
|
|
|
|
RSpec.describe InstructeurMailer, type: :mailer do
|
2018-02-23 13:09:57 +01:00
|
|
|
|
describe '#send_dossier' do
|
2019-08-06 11:02:54 +02:00
|
|
|
|
let(:sender) { create(:instructeur) }
|
|
|
|
|
let(:recipient) { create(:instructeur) }
|
2018-02-23 13:09:57 +01:00
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
subject { described_class.send_dossier(sender, dossier, recipient) }
|
|
|
|
|
|
|
|
|
|
it { expect(subject.body).to include('Bonjour') }
|
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
|
2024-05-23 19:09:04 +02:00
|
|
|
|
expect { subject.deliver_later }.to have_enqueued_job(PriorizedMailDeliveryJob).on_queue(custom_queue)
|
2023-10-18 07:10:26 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-02-23 13:09:57 +01:00
|
|
|
|
end
|
2018-02-23 13:11:29 +01:00
|
|
|
|
|
2023-01-23 14:56:05 +01:00
|
|
|
|
describe '#send_login_token' do
|
|
|
|
|
let(:user) { create(:instructeur) }
|
|
|
|
|
let(:token) { SecureRandom.hex }
|
2023-10-18 07:10:26 +02:00
|
|
|
|
subject { described_class.send_login_token(user, token) }
|
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
|
2023-01-23 14:56:05 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-02-23 13:11:29 +01:00
|
|
|
|
describe '#last_week_overview' do
|
2019-08-06 11:02:54 +02:00
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
|
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
|
2018-02-23 13:11:29 +01:00
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
let(:last_week_overview) do
|
|
|
|
|
procedure_overview = double('po',
|
|
|
|
|
procedure: procedure,
|
|
|
|
|
created_dossiers_count: 0,
|
|
|
|
|
dossiers_en_construction_count: 1,
|
|
|
|
|
old_dossiers_en_construction: [dossier],
|
|
|
|
|
dossiers_en_construction_description: 'desc',
|
|
|
|
|
dossiers_en_instruction_count: 1,
|
|
|
|
|
old_dossiers_en_instruction: [dossier],
|
|
|
|
|
dossiers_en_instruction_description: 'desc')
|
|
|
|
|
|
|
|
|
|
{
|
2018-10-25 15:07:15 +02:00
|
|
|
|
start_date: Time.zone.now,
|
2018-02-23 13:11:29 +01:00
|
|
|
|
procedure_overviews: [procedure_overview]
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
before { allow(instructeur).to receive(:last_week_overview).and_return(last_week_overview) }
|
2018-02-23 13:11:29 +01:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
subject { described_class.last_week_overview(instructeur) }
|
2018-02-23 13:11:29 +01:00
|
|
|
|
|
2018-05-31 15:50:13 +02:00
|
|
|
|
it { expect(subject.body).to include('Votre activité hebdomadaire') }
|
2019-04-04 10:41:44 +02:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
context 'when the instructeur has no active procedures' do
|
2019-04-04 10:41:44 +02:00
|
|
|
|
let(:procedure) { nil }
|
|
|
|
|
let(:last_week_overview) { nil }
|
|
|
|
|
|
|
|
|
|
it 'doesn’t send the email' do
|
|
|
|
|
expect(subject.message).to be_kind_of(ActionMailer::Base::NullMail)
|
|
|
|
|
expect(subject.body).to be_blank
|
|
|
|
|
end
|
|
|
|
|
end
|
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
|
2018-02-23 13:11:29 +01:00
|
|
|
|
end
|
2018-02-23 13:09:57 +01:00
|
|
|
|
end
|