2019-03-13 17:59:33 +01:00
|
|
|
describe NotificationService do
|
2019-08-06 11:02:54 +02:00
|
|
|
describe '.send_instructeur_email_notification' do
|
2019-03-13 17:59:33 +01:00
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
|
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
allow(InstructeurMailer).to receive(:send_notifications)
|
2019-03-13 17:59:33 +01:00
|
|
|
.and_return(double(deliver_later: true))
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
subject { NotificationService.send_instructeur_email_notification }
|
2019-03-13 17:59:33 +01:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when a instructeur does not enable its email notification' do
|
2019-03-13 17:59:33 +01:00
|
|
|
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
2019-03-13 17:59:33 +01:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
before { create(:assign_to, instructeur: instructeur, procedure: procedure) }
|
2019-03-13 17:59:33 +01:00
|
|
|
|
|
|
|
it do
|
|
|
|
subject
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(InstructeurMailer).not_to have_received(:send_notifications)
|
2019-03-13 17:59:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'when a instructeur enables its email_notification on one procedure' do
|
|
|
|
let(:instructeur_with_email_notifications) { create(:instructeur) }
|
2019-03-13 17:59:33 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
create(:assign_to,
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur: instructeur_with_email_notifications,
|
2019-03-13 17:59:33 +01:00
|
|
|
procedure: procedure,
|
2020-02-27 11:09:19 +01:00
|
|
|
daily_email_notifications_enabled: true)
|
2019-03-13 17:59:33 +01:00
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context "when there is no activity on the instructeur's procedures" do
|
2019-03-13 17:59:33 +01:00
|
|
|
it do
|
|
|
|
subject
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(InstructeurMailer).not_to have_received(:send_notifications)
|
2019-03-13 17:59:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dossier en construction exists on this procedure' do
|
|
|
|
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
subject
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(InstructeurMailer).to have_received(:send_notifications)
|
2019-03-13 17:59:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a notification on this procedure' do
|
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
allow_any_instance_of(Instructeur).to receive(:notifications_for_procedure)
|
2019-03-13 17:59:33 +01:00
|
|
|
.and_return([12])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
subject
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(InstructeurMailer).to have_received(:send_notifications)
|
2019-03-13 17:59:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|