2023-11-06 15:15:51 +01:00
|
|
|
|
describe 'Inviting an expert:', js: true do
|
2019-10-21 12:16:26 +02:00
|
|
|
|
include ActiveJob::TestHelper
|
|
|
|
|
include ActionView::Helpers
|
|
|
|
|
|
2023-03-03 14:16:15 +01:00
|
|
|
|
let(:instructeur) { create(:instructeur, password: SECURE_PASSWORD) }
|
2021-02-28 22:20:24 +01:00
|
|
|
|
let(:expert) { create(:expert, password: expert_password) }
|
2021-03-18 13:53:05 +01:00
|
|
|
|
let(:expert2) { create(:expert, password: expert_password) }
|
2019-10-21 12:16:26 +02:00
|
|
|
|
let(:expert_password) { 'mot de passe d’expert' }
|
|
|
|
|
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
|
2019-08-21 09:09:20 +02:00
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
2022-11-10 22:21:14 +01:00
|
|
|
|
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs_public.filter(&:dossier_link?).filter_map(&:value)) }
|
2019-10-21 12:16:26 +02:00
|
|
|
|
|
2021-04-14 21:45:32 +02:00
|
|
|
|
before do
|
|
|
|
|
clear_emails
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-21 12:16:26 +02:00
|
|
|
|
context 'as an Instructeur' do
|
|
|
|
|
scenario 'I can invite an expert' do
|
2021-04-29 17:29:47 +02:00
|
|
|
|
allow(ClamavService).to receive(:safe_file?).and_return(true)
|
|
|
|
|
|
2020-02-05 17:38:24 +01:00
|
|
|
|
# assign instructeur to linked dossier
|
2020-02-11 17:38:04 +01:00
|
|
|
|
instructeur.assign_to_procedure(linked_dossier.procedure)
|
2020-02-05 17:38:24 +01:00
|
|
|
|
|
2019-10-21 12:16:26 +02:00
|
|
|
|
login_as instructeur.user, scope: :user
|
|
|
|
|
visit instructeur_dossier_path(procedure, dossier)
|
|
|
|
|
|
|
|
|
|
click_on 'Avis externes'
|
|
|
|
|
expect(page).to have_current_path(avis_instructeur_dossier_path(procedure, dossier))
|
2023-03-17 11:30:20 +01:00
|
|
|
|
within('.fr-sidemenu') { click_on 'Demander un avis' }
|
|
|
|
|
expect(page).to have_current_path(avis_new_instructeur_dossier_path(procedure, dossier))
|
2019-10-21 12:16:26 +02:00
|
|
|
|
|
2021-03-30 17:55:35 +02:00
|
|
|
|
page.execute_script("document.querySelector('#avis_emails').value = '[\"#{expert.email}\",\"#{expert2.email}\"]'")
|
2019-10-21 12:16:26 +02:00
|
|
|
|
fill_in 'avis_introduction', with: 'Bonjour, merci de me donner votre avis sur ce dossier.'
|
2019-08-21 09:09:20 +02:00
|
|
|
|
check 'avis_invite_linked_dossiers'
|
2019-10-21 12:16:26 +02:00
|
|
|
|
page.select 'confidentiel', from: 'avis_confidentiel'
|
|
|
|
|
|
2023-03-17 11:30:20 +01:00
|
|
|
|
within('form#new_avis') { click_on 'Demander un avis' }
|
2021-03-11 14:42:57 +01:00
|
|
|
|
perform_enqueued_jobs
|
2019-10-21 12:16:26 +02:00
|
|
|
|
|
2021-05-26 15:16:30 +02:00
|
|
|
|
expect(page).to have_content('Une demande d’avis a été envoyée')
|
2019-10-21 12:16:26 +02:00
|
|
|
|
expect(page).to have_content('Avis des invités')
|
2023-03-24 15:09:54 +01:00
|
|
|
|
within('section') do
|
2021-03-18 13:53:05 +01:00
|
|
|
|
expect(page).to have_content(expert.email.to_s)
|
|
|
|
|
expect(page).to have_content(expert2.email.to_s)
|
2019-10-21 12:16:26 +02:00
|
|
|
|
expect(page).to have_content('Bonjour, merci de me donner votre avis sur ce dossier.')
|
|
|
|
|
end
|
|
|
|
|
|
2019-08-21 09:09:20 +02:00
|
|
|
|
expect(Avis.count).to eq(4)
|
2021-03-18 13:53:05 +01:00
|
|
|
|
expect(emails_sent_to(expert.email.to_s).size).to eq(1)
|
|
|
|
|
expect(emails_sent_to(expert2.email.to_s).size).to eq(1)
|
|
|
|
|
invitation_email = open_email(expert.email.to_s)
|
2022-05-23 15:09:22 +02:00
|
|
|
|
targeted_user_link = TargetedUserLink.joins(:user).where(user: { email: expert.email.to_s }).first
|
|
|
|
|
targeted_user_url = targeted_user_link_url(targeted_user_link)
|
|
|
|
|
expect(invitation_email.body).to include(targeted_user_url)
|
2019-10-21 12:16:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
2024-02-02 17:30:12 +01:00
|
|
|
|
scenario 'I can paste a list of experts emails' do
|
|
|
|
|
allow(ClamavService).to receive(:safe_file?).and_return(true)
|
|
|
|
|
|
|
|
|
|
# assign instructeur to linked dossier
|
|
|
|
|
instructeur.assign_to_procedure(linked_dossier.procedure)
|
|
|
|
|
|
|
|
|
|
login_as instructeur.user, scope: :user
|
|
|
|
|
visit instructeur_dossier_path(procedure, dossier)
|
|
|
|
|
|
|
|
|
|
click_on 'Avis externes'
|
|
|
|
|
expect(page).to have_current_path(avis_instructeur_dossier_path(procedure, dossier))
|
|
|
|
|
within('.fr-sidemenu') { click_on 'Demander un avis' }
|
|
|
|
|
expect(page).to have_current_path(avis_new_instructeur_dossier_path(procedure, dossier))
|
|
|
|
|
|
|
|
|
|
fill_in 'Emails', with: "expert1@gouv.fr; expert2@gouv.fr; test@test.fr; email-invalide"
|
|
|
|
|
fill_in 'avis_introduction', with: 'Bonjour, merci de me donner votre avis sur ce dossier.'
|
|
|
|
|
check 'avis_invite_linked_dossiers'
|
|
|
|
|
page.select 'confidentiel', from: 'avis_confidentiel'
|
|
|
|
|
|
|
|
|
|
within('form#new_avis') { click_on 'Demander un avis' }
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('Une demande d’avis a été envoyée')
|
|
|
|
|
expect(page).to have_content('Avis des invités')
|
|
|
|
|
within('section') do
|
|
|
|
|
expect(page).to have_content('expert1@gouv.fr')
|
|
|
|
|
expect(page).to have_content('expert2@gouv.fr')
|
|
|
|
|
expect(page).to have_content('test@test.fr')
|
|
|
|
|
expect(page).not_to have_content('email-invalide')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when experts list is restricted by admin' do
|
|
|
|
|
let!(:expert_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure, allow_decision_access: true) }
|
|
|
|
|
let(:expert_email) { expert.email }
|
|
|
|
|
let(:expert2_email) { expert2.email }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
procedure.update!(experts_require_administrateur_invitation: true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'only allowed experts are invited' do
|
|
|
|
|
allow(ClamavService).to receive(:safe_file?).and_return(true)
|
|
|
|
|
|
|
|
|
|
# assign instructeur to linked dossier
|
|
|
|
|
instructeur.assign_to_procedure(linked_dossier.procedure)
|
|
|
|
|
|
|
|
|
|
login_as instructeur.user, scope: :user
|
|
|
|
|
visit instructeur_dossier_path(procedure, dossier)
|
|
|
|
|
|
|
|
|
|
click_on 'Avis externes'
|
|
|
|
|
expect(page).to have_current_path(avis_instructeur_dossier_path(procedure, dossier))
|
|
|
|
|
within('.fr-sidemenu') { click_on 'Demander un avis' }
|
|
|
|
|
expect(page).to have_current_path(avis_new_instructeur_dossier_path(procedure, dossier))
|
|
|
|
|
|
|
|
|
|
fill_in 'Emails', with: "#{expert.email}; #{expert2.email}"
|
|
|
|
|
fill_in 'avis_introduction', with: 'Bonjour, merci de me donner votre avis sur ce dossier.'
|
|
|
|
|
check 'avis_invite_linked_dossiers'
|
|
|
|
|
page.select 'confidentiel', from: 'avis_confidentiel'
|
|
|
|
|
|
|
|
|
|
within('form#new_avis') { click_on 'Demander un avis' }
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('Une demande d’avis a été envoyée')
|
|
|
|
|
expect(page).to have_content('Avis des invités')
|
|
|
|
|
within('section') do
|
|
|
|
|
expect(page).to have_content(expert.email)
|
|
|
|
|
expect(page).not_to have_content(expert2.email)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-21 12:16:26 +02:00
|
|
|
|
context 'when experts submitted their answer' do
|
2021-03-23 12:25:57 +01:00
|
|
|
|
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
2021-02-28 22:20:24 +01:00
|
|
|
|
let!(:answered_avis) { create(:avis, :with_answer, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) }
|
2019-10-21 12:16:26 +02:00
|
|
|
|
|
|
|
|
|
scenario 'I can read the expert answer' do
|
|
|
|
|
login_as instructeur.user, scope: :user
|
|
|
|
|
visit instructeur_dossier_path(procedure, dossier)
|
|
|
|
|
|
|
|
|
|
click_on 'Avis externes'
|
|
|
|
|
|
2021-02-28 22:20:24 +01:00
|
|
|
|
expect(page).to have_content(answered_avis.expert.email)
|
2023-02-22 11:47:58 +01:00
|
|
|
|
answered_avis.answer.split("\n").map { |line| line.gsub("- ", "") }.map do |answer_line|
|
2019-10-21 12:16:26 +02:00
|
|
|
|
expect(page).to have_content(answer_line)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|