Merge pull request #9487 from mfo/US/fix-expert-invitation

correctif(expert.invite-autre-expert): ETQ expert, je ne pouvais pas demander d'autres avis d'expert
This commit is contained in:
LeSim 2023-09-19 08:16:53 +00:00 committed by GitHub
commit 29c52d191e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 { _1.expert.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 }