From 30df608a99e570b09275283df66024134e26c2e1 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Fri, 15 Mar 2024 16:41:59 +0000 Subject: [PATCH] tests --- .../instructeurs/avis_controller_spec.rb | 2 +- .../instructeurs/dossiers_controller_spec.rb | 7 ++++ .../users/dossiers_controller_spec.rb | 35 ++++++++++++++----- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 6f1b57a8a..819a8887d 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -5,7 +5,7 @@ describe Instructeurs::AvisController, type: :controller do let(:now) { Time.zone.parse('01/02/2345') } let(:expert) { create(:expert) } let(:claimant) { create(:instructeur) } - let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) } + let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure, notify_on_new_avis: false) } let(:instructeur) { create(:instructeur) } let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index 08900e03e..67316d102 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -826,6 +826,13 @@ describe Instructeurs::DossiersController, type: :controller do it { expect(saved_avis.expert.email).to eq("titi@titimail.com") } end + context 'when the expert do not want to receive notification' do + let(:emails) { "[\"email@a.com\"]" } + let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure, notify_on_new_avis: false) } + + before { subject } + end + context 'with linked dossiers' do let(:asked_confidentiel) { false } let(:previous_avis_confidentiel) { false } diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 1f7165377..b5ca8f810 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -1197,21 +1197,38 @@ describe Users::DossiersController, type: :controller do end end - context 'email notification to experts' do + context 'notify on new message to experts' do let(:expert) { create(:expert) } - let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) } + let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure, notify_on_new_message: true) } let(:avis) { create(:avis, dossier: dossier, claimant: instructeur_with_instant_message, experts_procedure: experts_procedure) } let(:avis2) { create(:avis, dossier: dossier, claimant: instructeur_with_instant_message, experts_procedure: experts_procedure) } - before do - allow(AvisMailer).to receive(:notify_new_commentaire_to_expert).and_return(double(deliver_later: nil)) - avis - avis2 - subject + context 'when notify_on_new_message is true' do + before do + allow(AvisMailer).to receive(:notify_new_commentaire_to_expert).and_return(double(deliver_later: nil)) + avis + avis2 + subject + end + + it 'sends just one email to the expert linked to several avis on the same dossier' do + expect(AvisMailer).to have_received(:notify_new_commentaire_to_expert).with(dossier, avis, expert).once + end end - it 'sends just one email to the expert linked to several avis on the same dossier' do - expect(AvisMailer).to have_received(:notify_new_commentaire_to_expert).with(dossier, avis, expert).once + context 'when notify_on_new_message is false' do + let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure, notify_on_new_message: false) } + + before do + allow(AvisMailer).to receive(:notify_new_commentaire_to_expert).and_return(double(deliver_later: nil)) + avis + avis2 + subject + end + + it 'does not send any email to the expert' do + expect(AvisMailer).not_to have_received(:notify_new_commentaire_to_expert) + end end end