This commit is contained in:
Kara Diaby 2024-03-15 16:41:59 +00:00
parent e824118aea
commit 30df608a99
3 changed files with 34 additions and 10 deletions

View file

@ -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) }

View file

@ -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 }

View file

@ -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