2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
|
2020-03-13 10:24:25 +01:00
|
|
|
context 'when a declarative dossier in instruction exists on this procedure' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2020-03-13 10:24:25 +01:00
|
|
|
before do
|
|
|
|
procedure.update(declarative_with_state: "en_instruction")
|
2022-12-02 18:15:43 +01:00
|
|
|
dossier.process_declarative!
|
2020-03-13 10:24:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(InstructeurMailer).to have_received(:send_notifications)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a declarative dossier in accepte on yesterday exists on this procedure' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2020-03-13 10:24:25 +01:00
|
|
|
before do
|
|
|
|
procedure.update(declarative_with_state: "accepte")
|
2022-12-02 18:15:43 +01:00
|
|
|
dossier.process_declarative!
|
2020-07-02 11:02:50 +02:00
|
|
|
dossier.traitements.last.update!(processed_at: Time.zone.yesterday.beginning_of_day)
|
2020-03-13 10:24:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(InstructeurMailer).to have_received(:send_notifications)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a declarative dossier in accepte on today exists on this procedure' do
|
2022-12-02 18:15:43 +01:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2020-03-13 10:24:25 +01:00
|
|
|
before do
|
|
|
|
procedure.update(declarative_with_state: "accepte")
|
2022-12-02 18:15:43 +01:00
|
|
|
dossier.process_declarative!
|
2020-03-13 10:24:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(InstructeurMailer).not_to have_received(:send_notifications)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-13 17:59:33 +01:00
|
|
|
context 'when there is a notification on this procedure' do
|
|
|
|
before do
|
2021-04-07 18:03:03 +02:00
|
|
|
allow_any_instance_of(Instructeur).to receive(:notifications_for_groupe_instructeurs)
|
|
|
|
.and_return(en_cours: [12], termines: [])
|
2019-03-13 17:59:33 +01:00
|
|
|
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
|