From 5d0a8b567fb27d8ff175f8de5a4bf0c47e134ccc Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 11 Feb 2020 17:18:49 +0100 Subject: [PATCH] specs: improve description of Avis creation test cases --- .../instructeurs/avis_controller_spec.rb | 37 ++++++++----- .../instructeurs/dossiers_controller_spec.rb | 54 ++++++++++++++++++- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index a071a0cef..490668834 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -187,17 +187,21 @@ describe Instructeurs::AvisController, type: :controller do let(:previous_avis_confidentiel) { false } let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) } - it do - expect(flash.notice).to eq("Une demande d'avis a été envoyée à a@b.com") - expect(Avis.count).to eq(old_avis_count + 1) - expect(created_avis.email).to eq("a@b.com") - expect(created_avis.dossier).to eq(dossier) + context 'when the expert doesn’t share linked dossiers' do + let(:invite_linked_dossiers) { false } + + it 'sends a single avis for the main dossier, but doesn’t give access to the linked dossiers' do + expect(flash.notice).to eq("Une demande d'avis a été envoyée à a@b.com") + expect(Avis.count).to eq(old_avis_count + 1) + expect(created_avis.email).to eq("a@b.com") + expect(created_avis.dossier).to eq(dossier) + end end - context 'checked' do + context 'when the expert also shares the linked dossiers' do let(:invite_linked_dossiers) { true } - context 'and can access linked dossiers' do + context 'and the expert can access the linked dossiers' do let(:created_avis) { Avis.last(2).first } let(:linked_avis) { Avis.last } let(:linked_dossier) { dossier.reload.linked_dossiers.first } @@ -206,20 +210,25 @@ describe Instructeurs::AvisController, type: :controller do true end - it 'sends two avis invitations' do + it 'sends one avis for the main dossier' do expect(flash.notice).to eq("Une demande d'avis a été envoyée à a@b.com") - expect(Avis.count).to eq(old_avis_count + 2) expect(created_avis.email).to eq("a@b.com") expect(created_avis.dossier).to eq(dossier) + end + + it 'sends another avis for the linked dossiers' do + expect(Avis.count).to eq(old_avis_count + 2) expect(linked_avis.dossier).to eq(linked_dossier) end end - it 'and can not access linked dossiers' do - expect(flash.notice).to eq("Une demande d'avis a été envoyée à a@b.com") - expect(Avis.count).to eq(old_avis_count + 1) - expect(created_avis.email).to eq("a@b.com") - expect(created_avis.dossier).to eq(dossier) + context 'but the expert can’t access the linked dossier' do + it 'sends a single avis for the main dossier, but doesn’t give access to the linked dossiers' do + expect(flash.notice).to eq("Une demande d'avis a été envoyée à a@b.com") + expect(Avis.count).to eq(old_avis_count + 1) + expect(created_avis.email).to eq("a@b.com") + expect(created_avis.dossier).to eq(dossier) + end end end end diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index f080ab548..032c986cb 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -430,6 +430,7 @@ describe Instructeurs::DossiersController, type: :controller do end describe "#create_avis" do + let(:invite_linked_dossiers) { false } let(:saved_avis) { dossier.avis.first } let!(:old_avis_count) { Avis.count } @@ -437,7 +438,7 @@ describe Instructeurs::DossiersController, type: :controller do post :create_avis, params: { procedure_id: procedure.id, dossier_id: dossier.id, - avis: { emails: emails, introduction: 'intro', confidentiel: true } + avis: { emails: emails, introduction: 'intro', confidentiel: true, invite_linked_dossiers: invite_linked_dossiers } } end @@ -471,6 +472,57 @@ describe Instructeurs::DossiersController, type: :controller do it { expect(Avis.count).to eq(old_avis_count + 1) } it { expect(saved_avis.email).to eq("titi@titimail.com") } end + + context 'with linked dossiers' do + let(:asked_confidentiel) { false } + let(:previous_avis_confidentiel) { false } + let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) } + + context 'when the expert doesn’t share linked dossiers' do + let(:invite_linked_dossiers) { false } + + it 'sends a single avis for the main dossier, but doesn’t give access to the linked dossiers' do + expect(flash.notice).to eq("Une demande d'avis a été envoyée à email@a.com") + expect(Avis.count).to eq(old_avis_count + 1) + expect(saved_avis.email).to eq("email@a.com") + expect(saved_avis.dossier).to eq(dossier) + end + end + + context 'when the expert also shares the linked dossiers' do + let(:invite_linked_dossiers) { true } + + context 'and the expert can access the linked dossiers' do + let(:saved_avis) { Avis.last(2).first } + let(:linked_avis) { Avis.last } + let(:linked_dossier) { dossier.reload.linked_dossiers.first } + let(:invite_linked_dossiers) do + instructeur.assign_to_procedure(linked_dossier.procedure) + true + end + + it 'sends one avis for the main dossier' do + expect(flash.notice).to eq("Une demande d'avis a été envoyée à email@a.com") + expect(saved_avis.email).to eq("email@a.com") + expect(saved_avis.dossier).to eq(dossier) + end + + it 'sends another avis for the linked dossiers' do + expect(Avis.count).to eq(old_avis_count + 2) + expect(linked_avis.dossier).to eq(linked_dossier) + end + end + + context 'but the expert can’t access the linked dossier' do + it 'sends a single avis for the main dossier, but doesn’t give access to the linked dossiers' do + expect(flash.notice).to eq("Une demande d'avis a été envoyée à email@a.com") + expect(Avis.count).to eq(old_avis_count + 1) + expect(saved_avis.email).to eq("email@a.com") + expect(saved_avis.dossier).to eq(dossier) + end + end + end + end end describe "#show" do