test fonctionnel notifications avis
This commit is contained in:
parent
bfd24e8aee
commit
52d5a52ff9
1 changed files with 82 additions and 63 deletions
|
@ -445,79 +445,64 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
|
||||||
subject
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:emails) { ['email@a.com'] }
|
let(:emails) { ['email@a.com'] }
|
||||||
|
|
||||||
it { expect(saved_avis.email).to eq('email@a.com') }
|
context "notifications updates" do
|
||||||
it { expect(saved_avis.introduction).to eq('intro') }
|
context 'when an instructeur follows the dossier' do
|
||||||
it { expect(saved_avis.confidentiel).to eq(true) }
|
let(:follower) { create(:instructeur) }
|
||||||
it { expect(saved_avis.dossier).to eq(dossier) }
|
before { follower.follow(dossier) }
|
||||||
it { expect(saved_avis.claimant).to eq(instructeur) }
|
|
||||||
it { expect(response).to redirect_to(avis_instructeur_dossier_path(dossier.procedure, dossier)) }
|
|
||||||
|
|
||||||
context "with an invalid email" do
|
it 'the follower has a notification' do
|
||||||
let(:emails) { ['emaila.com'] }
|
expect(follower.followed_dossiers.with_notifications(follower)).to eq([])
|
||||||
|
subject
|
||||||
it { expect(response).to render_template :avis }
|
expect(follower.followed_dossiers.with_notifications(follower)).to eq([dossier.reload])
|
||||||
it { expect(flash.alert).to eq(["emaila.com : Email n'est pas valide"]) }
|
|
||||||
it { expect { subject }.not_to change(Avis, :count) }
|
|
||||||
it { expect(dossier.last_avis_updated_at).to eq(nil) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with multiple emails' do
|
|
||||||
let(:emails) { ["toto.fr,titi@titimail.com"] }
|
|
||||||
|
|
||||||
it { expect(response).to render_template :avis }
|
|
||||||
it { expect(flash.alert).to eq(["toto.fr : Email n'est pas valide"]) }
|
|
||||||
it { expect(flash.notice).to eq("Une demande d'avis a été envoyée à titi@titimail.com") }
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the expert also shares the linked dossiers' do
|
context 'email sending' do
|
||||||
let(:invite_linked_dossiers) { true }
|
before do
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
context 'and the expert can access the linked dossiers' do
|
it { expect(saved_avis.email).to eq('email@a.com') }
|
||||||
let(:saved_avis) { Avis.last(2).first }
|
it { expect(saved_avis.introduction).to eq('intro') }
|
||||||
let(:linked_avis) { Avis.last }
|
it { expect(saved_avis.confidentiel).to eq(true) }
|
||||||
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs.filter(&:dossier_link?).map(&:value).compact) }
|
it { expect(saved_avis.dossier).to eq(dossier) }
|
||||||
let(:invite_linked_dossiers) do
|
it { expect(saved_avis.claimant).to eq(instructeur) }
|
||||||
instructeur.assign_to_procedure(linked_dossier.procedure)
|
it { expect(response).to redirect_to(avis_instructeur_dossier_path(dossier.procedure, dossier)) }
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'sends one avis for the main dossier' do
|
context "with an invalid email" do
|
||||||
expect(flash.notice).to eq("Une demande d'avis a été envoyée à email@a.com")
|
let(:emails) { ['emaila.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
|
before { subject }
|
||||||
expect(Avis.count).to eq(old_avis_count + 2)
|
|
||||||
expect(linked_avis.dossier).to eq(linked_dossier)
|
it { expect(response).to render_template :avis }
|
||||||
end
|
it { expect(flash.alert).to eq(["emaila.com : Email n'est pas valide"]) }
|
||||||
end
|
it { expect { subject }.not_to change(Avis, :count) }
|
||||||
|
it { expect(dossier.last_avis_updated_at).to eq(nil) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with multiple emails' do
|
||||||
|
let(:emails) { ["toto.fr,titi@titimail.com"] }
|
||||||
|
|
||||||
|
before { subject }
|
||||||
|
|
||||||
|
it { expect(response).to render_template :avis }
|
||||||
|
it { expect(flash.alert).to eq(["toto.fr : Email n'est pas valide"]) }
|
||||||
|
it { expect(flash.notice).to eq("Une demande d'avis a été envoyée à titi@titimail.com") }
|
||||||
|
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) }
|
||||||
|
before { subject }
|
||||||
|
context 'when the expert doesn’t share linked dossiers' do
|
||||||
|
let(:invite_linked_dossiers) { false }
|
||||||
|
|
||||||
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
|
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(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(Avis.count).to eq(old_avis_count + 1)
|
||||||
|
@ -525,6 +510,40 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
expect(saved_avis.dossier).to eq(dossier)
|
expect(saved_avis.dossier).to eq(dossier)
|
||||||
end
|
end
|
||||||
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.find_by(id: dossier.reload.champs.filter(&:dossier_link?).map(&:value).compact) }
|
||||||
|
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue