specs: improve description of Avis creation test cases
This commit is contained in:
parent
f0ea96772d
commit
5d0a8b567f
2 changed files with 76 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue