From a52aeb6fdc77d21cc19a32ccbc1bd50eb73f3edc Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Wed, 31 Aug 2022 16:23:46 +0200 Subject: [PATCH] tests --- .../experts/avis_controller_spec.rb | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/spec/controllers/experts/avis_controller_spec.rb b/spec/controllers/experts/avis_controller_spec.rb index 655d21b63..8c492e4d0 100644 --- a/spec/controllers/experts/avis_controller_spec.rb +++ b/spec/controllers/experts/avis_controller_spec.rb @@ -4,10 +4,11 @@ describe Experts::AvisController, type: :controller do let(:now) { Time.zone.parse('01/02/2345') } let(:instructeur) { create(:instructeur) } + let!(:instructeur_with_instant_avis_notification) { create(:instructeur) } let(:another_instructeur) { create(:instructeur) } let(:claimant) { create(:expert) } let(:expert) { create(:expert) } - let(:procedure) { create(:procedure, :published, instructeurs: [instructeur, another_instructeur]) } + let(:procedure) { create(:procedure, :published, instructeurs: [instructeur, another_instructeur, instructeur_with_instant_avis_notification]) } let(:another_procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) } @@ -155,6 +156,38 @@ describe Experts::AvisController, type: :controller do end end + context 'without attachment with an instructeur wants to be notified' do + before do + allow(DossierMailer).to receive(:notify_new_avis_to_instructeur).and_return(double(deliver_later: nil)) + AssignTo.find_by(instructeur: instructeur_with_instant_avis_notification).update!(instant_expert_avis_email_notifications_enabled: true) + Timecop.freeze(now) + instructeur_with_instant_avis_notification.follow(avis_without_answer.dossier) + patch :update, params: { id: avis_without_answer.id, procedure_id: procedure.id, avis: { answer: 'answer' } } + avis_without_answer.reload + end + after { Timecop.return } + + it 'The instructeur should be notified of the new avis' do + expect(DossierMailer).to have_received(:notify_new_avis_to_instructeur).once.with(avis_without_answer, instructeur_with_instant_avis_notification.email) + end + end + + context 'without attachment with an instructeur wants to be notified' do + before do + allow(DossierMailer).to receive(:notify_new_avis_to_instructeur).and_return(double(deliver_later: nil)) + AssignTo.find_by(instructeur: instructeur_with_instant_avis_notification).update!(instant_expert_avis_email_notifications_enabled: true) + Timecop.freeze(now) + instructeur_with_instant_avis_notification.follow(avis_without_answer.dossier) + patch :update, params: { id: avis_without_answer.id, procedure_id: procedure.id, avis: { answer: 'answer' } } + avis_without_answer.reload + end + after { Timecop.return } + + it 'The instructeur should be notified of the new avis' do + expect(DossierMailer).to have_received(:notify_new_avis_to_instructeur).once.with(avis_without_answer, instructeur_with_instant_avis_notification.email) + end + end + context 'with attachment' do include ActiveJob::TestHelper let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }