correctif(expert.invite-autre-expert): ETQ expert, je ne pouvais pas demander d'autres avis d'expert

This commit is contained in:
Martin 2023-09-18 16:23:42 +02:00
parent ae2d9bba47
commit aa10f23b43
2 changed files with 28 additions and 0 deletions

View file

@ -65,6 +65,11 @@ module Experts
def avis_new
@new_avis = Avis.new
if @dossier.procedure.experts_require_administrateur_invitation?
@experts_emails = @dossier.procedure.experts_procedures.where(revoked_at: nil).map(&:expert).map(&:email).sort
else
@experts_emails = @dossier.procedure.experts.map(&:email).sort
end
end
def create_avis

View file

@ -356,6 +356,29 @@ describe Experts::AvisController, type: :controller do
end
end
describe '#avis_new' do
let!(:revoked_expert) { create(:experts_procedure, revoked_at: 2.days.ago, procedure: procedure, expert: create(:expert)).expert }
before do
get :avis_new, params: { procedure_id: procedure.id, id: avis_without_answer.id }
end
context 'when procedure experts need administrateur invitation' do
let!(:procedure) { create(:procedure, experts_require_administrateur_invitation: true) }
it 'limit invited email list to not revoked experts' do
expect(assigns(:experts_emails)).to include(experts_procedure.expert.user.email)
expect(assigns(:experts_emails)).not_to include(revoked_expert.user.email)
end
end
context 'when procedure experts can be anyone' do
let!(:procedure) { create(:procedure, experts_require_administrateur_invitation: false) }
it 'prefill autocomplete with all experts in the procedure' do
expect(assigns(:experts_emails)).to include(experts_procedure.expert.user.email)
expect(assigns(:experts_emails)).to include(revoked_expert.user.email)
end
end
end
describe '#create_avis' do
let(:previous_avis_confidentiel) { false }
let(:previous_revoked_at) { nil }