2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-25 13:02:22 +01:00
|
|
|
RSpec.describe ExpertsProcedure, type: :model do
|
|
|
|
describe '#invited_expert_emails' do
|
|
|
|
let!(:procedure) { create(:procedure, :published) }
|
2021-02-28 22:20:24 +01:00
|
|
|
let(:claimant) { create(:instructeur) }
|
2021-01-25 13:02:22 +01:00
|
|
|
let(:expert) { create(:expert) }
|
|
|
|
let(:expert2) { create(:expert) }
|
|
|
|
let(:expert3) { create(:expert) }
|
2021-03-23 12:25:57 +01:00
|
|
|
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
|
|
|
let(:experts_procedure2) { create(:experts_procedure, expert: expert2, procedure: procedure) }
|
|
|
|
let(:experts_procedure3) { create(:experts_procedure, expert: expert3, procedure: procedure) }
|
2021-02-11 19:32:48 +01:00
|
|
|
subject { procedure.experts_procedures }
|
2021-01-25 13:02:22 +01:00
|
|
|
|
|
|
|
context 'when there is one dossier' do
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
|
|
|
context 'when a procedure has one avis and known instructeur' do
|
2021-02-28 22:20:24 +01:00
|
|
|
let!(:avis) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) }
|
2021-01-25 13:02:22 +01:00
|
|
|
|
2021-02-11 19:32:48 +01:00
|
|
|
it { is_expected.to eq([experts_procedure]) }
|
|
|
|
it { expect(procedure.experts.count).to eq(1) }
|
|
|
|
it { expect(procedure.experts.first.email).to eq(expert.email) }
|
2021-01-25 13:02:22 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dossier has 2 avis from the same expert' do
|
|
|
|
let!(:avis) { create(:avis, dossier: dossier, experts_procedure: experts_procedure) }
|
|
|
|
let!(:avis2) { create(:avis, dossier: dossier, experts_procedure: experts_procedure) }
|
|
|
|
|
2021-02-11 19:32:48 +01:00
|
|
|
it { is_expected.to eq([experts_procedure]) }
|
|
|
|
it { expect(procedure.experts.count).to eq(1) }
|
|
|
|
it { expect(procedure.experts.first).to eq(expert) }
|
2021-01-25 13:02:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are two dossiers' do
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
let!(:dossier2) { create(:dossier, procedure: procedure) }
|
|
|
|
|
|
|
|
context 'and each one has an avis from 3 different experts' do
|
|
|
|
let!(:avis) { create(:avis, dossier: dossier, experts_procedure: experts_procedure) }
|
|
|
|
let!(:avis2) { create(:avis, dossier: dossier2, experts_procedure: experts_procedure2) }
|
|
|
|
let!(:avis3) { create(:avis, dossier: dossier2, experts_procedure: experts_procedure3) }
|
|
|
|
|
2021-02-11 19:32:48 +01:00
|
|
|
it { is_expected.to match_array([experts_procedure, experts_procedure2, experts_procedure3]) }
|
|
|
|
it { expect(procedure.experts.count).to eq(3) }
|
|
|
|
it { expect(procedure.experts).to match_array([expert, expert2, expert3]) }
|
2021-01-25 13:02:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|