2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-10-26 11:44:53 +02:00
|
|
|
|
describe 'Inviting an expert:' do
|
2021-02-28 22:20:24 +01:00
|
|
|
|
include ActiveJob::TestHelper
|
|
|
|
|
include ActionView::Helpers
|
|
|
|
|
|
|
|
|
|
context 'as an invited Expert' do
|
|
|
|
|
let(:expert) { create(:expert) }
|
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:types_de_champ_private) { [] }
|
|
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :piece_justificative }, { type: :dossier_link }], types_de_champ_private:, instructeurs: [instructeur]) }
|
|
|
|
|
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure:) }
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, :with_populated_annotations, procedure:) }
|
|
|
|
|
let(:champ) { dossier.champs.first }
|
2021-02-28 22:20:24 +01:00
|
|
|
|
let(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) }
|
2023-03-06 17:09:42 +01:00
|
|
|
|
let(:avis_with_question) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true, question_label: 'Question ?') }
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:dossier_accepte) { create(:dossier, :accepte, procedure:) }
|
2023-04-03 17:05:17 +02:00
|
|
|
|
let(:avis_on_dossier_accepte) { create(:avis, dossier: dossier_accepte, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) }
|
2021-02-28 22:20:24 +01:00
|
|
|
|
|
|
|
|
|
context 'when I don’t already have an account' do
|
2021-06-29 12:41:33 +02:00
|
|
|
|
let(:password) { 'This is an expert password' }
|
|
|
|
|
|
|
|
|
|
before 'Signing up' do
|
2021-06-15 18:44:33 +02:00
|
|
|
|
visit sign_up_expert_avis_path(avis.dossier.procedure, avis, email: avis.expert.email)
|
2021-02-28 22:20:24 +01:00
|
|
|
|
|
2024-02-16 14:21:47 +01:00
|
|
|
|
expect(page).to have_field('Adresse électronique', with: avis.expert.email, disabled: true)
|
2021-06-29 12:41:33 +02:00
|
|
|
|
fill_in 'Mot de passe', with: password
|
2021-02-28 22:20:24 +01:00
|
|
|
|
click_on 'Créer un compte'
|
2021-06-29 12:41:33 +02:00
|
|
|
|
end
|
2021-02-28 22:20:24 +01:00
|
|
|
|
|
2021-06-29 12:41:33 +02:00
|
|
|
|
scenario 'I can see the avis after signing up' do
|
2021-02-28 22:20:24 +01:00
|
|
|
|
expect(page).to have_current_path(expert_all_avis_path)
|
|
|
|
|
expect(page).to have_text('1 avis à donner')
|
|
|
|
|
end
|
2021-06-29 12:41:33 +02:00
|
|
|
|
|
|
|
|
|
scenario 'I can sign-in again afterwards' do
|
|
|
|
|
click_on 'Se déconnecter'
|
|
|
|
|
|
|
|
|
|
visit new_user_session_path
|
|
|
|
|
sign_in_with avis.expert.email, password
|
|
|
|
|
|
2023-12-19 11:22:50 +01:00
|
|
|
|
expect(page).to have_content('Vous pouvez à tout moment alterner entre vos différents profils : expert, usager.')
|
2023-12-14 10:07:34 +01:00
|
|
|
|
expect(page).to have_current_path(expert_all_avis_path)
|
2021-06-29 12:41:33 +02:00
|
|
|
|
end
|
2021-02-28 22:20:24 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when I already have an existing account' do
|
|
|
|
|
before do
|
|
|
|
|
avis.expert.user.update!(last_sign_in_at: Time.zone.now)
|
|
|
|
|
avis.expert.user.reload
|
|
|
|
|
end
|
|
|
|
|
scenario 'I can sign in' do
|
2021-06-15 18:44:33 +02:00
|
|
|
|
visit sign_up_expert_avis_path(avis.dossier.procedure, avis, email: avis.expert.email)
|
2021-02-28 22:20:24 +01:00
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path(new_user_session_path)
|
|
|
|
|
login_as avis.expert.user, scope: :user
|
|
|
|
|
sign_in_with(avis.expert.email, 'This is a very complicated password !')
|
2023-12-14 10:11:54 +01:00
|
|
|
|
expect(page).to have_content("connecté en tant qu’expert")
|
2023-12-14 10:07:34 +01:00
|
|
|
|
click_on 'Passer en usager'
|
|
|
|
|
expect(page).to have_current_path(dossiers_path)
|
2021-02-28 22:20:24 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'I can give an answer' do
|
|
|
|
|
avis # create avis
|
2023-04-03 17:05:17 +02:00
|
|
|
|
avis_on_dossier_accepte # create avis
|
2021-02-28 22:20:24 +01:00
|
|
|
|
login_as expert.user, scope: :user
|
|
|
|
|
|
|
|
|
|
visit expert_all_avis_path
|
|
|
|
|
expect(page).to have_text('1 avis à donner')
|
|
|
|
|
expect(page).to have_text('0 avis donnés')
|
|
|
|
|
|
2023-04-03 17:05:17 +02:00
|
|
|
|
expect(page).to have_selector('.badge', text: 1)
|
|
|
|
|
expect(page).to have_selector('.notifications')
|
|
|
|
|
|
2021-02-28 22:20:24 +01:00
|
|
|
|
click_on '1 avis à donner'
|
|
|
|
|
click_on avis.dossier.user.email
|
2023-11-09 15:02:43 +01:00
|
|
|
|
within('.fr-tabs') { click_on 'Avis' }
|
2021-02-28 22:20:24 +01:00
|
|
|
|
expect(page).to have_text("Demandeur : #{avis.claimant.email}")
|
|
|
|
|
expect(page).to have_text('Cet avis est confidentiel')
|
|
|
|
|
|
|
|
|
|
fill_in 'avis_answer', with: 'Ma réponse d’expert : c’est un oui.'
|
|
|
|
|
find('.attachment input[name="avis[piece_justificative_file]"]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf')
|
|
|
|
|
click_on 'Envoyer votre avis'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('Votre réponse est enregistrée')
|
|
|
|
|
expect(page).to have_content('Ma réponse d’expert : c’est un oui.')
|
|
|
|
|
expect(page).to have_content('RIB.pdf')
|
|
|
|
|
|
2023-03-30 17:54:14 +02:00
|
|
|
|
within('.fr-breadcrumb__list') { click_on 'Avis' }
|
2021-02-28 22:20:24 +01:00
|
|
|
|
expect(page).to have_text('0 avis à donner')
|
|
|
|
|
expect(page).to have_text('1 avis donné')
|
2023-04-03 17:05:17 +02:00
|
|
|
|
|
|
|
|
|
expect(page).not_to have_selector('.badge', text: 1)
|
|
|
|
|
expect(page).not_to have_selector('.notifications')
|
2021-02-28 22:20:24 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-06 17:09:42 +01:00
|
|
|
|
scenario 'I can give a yes/no answer to a question' do
|
|
|
|
|
avis_with_question # create avis
|
|
|
|
|
login_as expert.user, scope: :user
|
|
|
|
|
|
|
|
|
|
visit expert_all_avis_path
|
|
|
|
|
expect(page).to have_text('1 avis à donner')
|
|
|
|
|
expect(page).to have_text('0 avis donnés')
|
|
|
|
|
|
|
|
|
|
click_on '1 avis à donner'
|
|
|
|
|
click_on avis.dossier.user.email
|
2023-11-09 15:02:43 +01:00
|
|
|
|
within('.fr-tabs') { click_on 'Avis' }
|
2023-03-06 17:09:42 +01:00
|
|
|
|
expect(page).to have_text("Demandeur : #{avis.claimant.email}")
|
|
|
|
|
expect(page).to have_text('Question ?')
|
|
|
|
|
expect(page).to have_text('Cet avis est confidentiel')
|
|
|
|
|
|
2023-03-14 15:05:19 +01:00
|
|
|
|
# check validation
|
|
|
|
|
click_on 'Envoyer votre avis'
|
2023-03-21 17:07:05 +01:00
|
|
|
|
expect(page).to have_content("Le champ « Réponse oui/non » n'est pas inclus(e) dans la liste")
|
2023-03-14 15:05:19 +01:00
|
|
|
|
|
2023-03-21 17:07:05 +01:00
|
|
|
|
choose 'non'
|
2023-03-06 17:09:42 +01:00
|
|
|
|
fill_in 'avis_answer', with: 'Ma réponse d’expert.'
|
|
|
|
|
click_on 'Envoyer votre avis'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('Votre réponse est enregistrée')
|
|
|
|
|
expect(page).to have_content('Ma réponse d’expert.')
|
2023-03-21 17:07:05 +01:00
|
|
|
|
expect(page).to have_content('non')
|
2023-03-06 17:09:42 +01:00
|
|
|
|
|
2023-03-22 11:56:52 +01:00
|
|
|
|
click_on 'Voir les avis'
|
|
|
|
|
expect(page).to have_text('Vous')
|
|
|
|
|
expect(page).to have_text('non')
|
|
|
|
|
|
2023-03-30 17:54:14 +02:00
|
|
|
|
within('.fr-breadcrumb__list') { click_on 'Avis' }
|
2023-03-06 17:09:42 +01:00
|
|
|
|
expect(page).to have_text('1 avis donné')
|
|
|
|
|
end
|
|
|
|
|
|
2021-02-28 22:20:24 +01:00
|
|
|
|
# scenario 'I can invite other experts' do
|
|
|
|
|
# end
|
2021-09-27 15:07:56 +02:00
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
|
context 'with dossiers having attached files', js: true do
|
2021-09-27 15:07:56 +02:00
|
|
|
|
let(:path) { 'spec/fixtures/files/piece_justificative_0.pdf' }
|
|
|
|
|
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:types_de_champ_private) { [{ type: :piece_justificative }] }
|
2021-09-27 15:07:56 +02:00
|
|
|
|
|
|
|
|
|
scenario 'An Expert can download an archive containing attachments without any private champ, bill signature and operations logs' do
|
|
|
|
|
avis # create avis
|
|
|
|
|
login_as expert.user, scope: :user
|
|
|
|
|
visit expert_all_avis_path
|
|
|
|
|
|
|
|
|
|
click_on '1 avis à donner'
|
|
|
|
|
click_on avis.dossier.user.email
|
|
|
|
|
|
2024-09-10 23:53:04 +02:00
|
|
|
|
click_on 'Télécharger le dossier et toutes ses pièces jointes'
|
2021-09-27 15:07:56 +02:00
|
|
|
|
|
|
|
|
|
DownloadHelpers.wait_for_download
|
|
|
|
|
files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download))
|
|
|
|
|
expect(DownloadHelpers.download).to include "dossier-#{dossier.id}.zip"
|
|
|
|
|
expect(files.size).to be 2
|
|
|
|
|
expect(files[0].filename.include?('export')).to be_truthy
|
2024-07-01 15:31:32 +02:00
|
|
|
|
expect(files[1].filename.include?('toto')).to be_truthy
|
|
|
|
|
expect(files[1].uncompressed_size).to be 4
|
2021-09-27 15:07:56 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before { DownloadHelpers.clear_downloads }
|
|
|
|
|
after { DownloadHelpers.clear_downloads }
|
|
|
|
|
end
|
2021-02-28 22:20:24 +01:00
|
|
|
|
end
|
2021-05-25 10:54:04 +02:00
|
|
|
|
|
|
|
|
|
context 'when there are two experts' do
|
|
|
|
|
let(:expert_1) { create(:expert) }
|
|
|
|
|
let(:expert_2) { create(:expert) }
|
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur], types_de_champ_public: [{ type: :dossier_link }]) }
|
|
|
|
|
let(:experts_procedure_1) { create(:experts_procedure, expert: expert_1, procedure:) }
|
|
|
|
|
let(:experts_procedure_2) { create(:experts_procedure, expert: expert_2, procedure:) }
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:) }
|
2021-05-25 10:54:04 +02:00
|
|
|
|
let!(:avis_1) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_1, confidentiel: true) }
|
|
|
|
|
let!(:avis_2) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_2, confidentiel: false) }
|
|
|
|
|
|
|
|
|
|
scenario 'As a expert_1, I can read expert_2 advice because it is not confidential' do
|
|
|
|
|
login_as expert_1.user, scope: :user
|
|
|
|
|
|
|
|
|
|
visit expert_all_avis_path
|
|
|
|
|
expect(page).to have_text('1 avis à donner')
|
|
|
|
|
expect(page).to have_text('0 avis donnés')
|
|
|
|
|
|
|
|
|
|
click_on '1 avis à donner'
|
|
|
|
|
click_on avis_1.dossier.user.email
|
2023-11-09 15:02:43 +01:00
|
|
|
|
within('.fr-tabs') { click_on 'Avis' }
|
2021-05-25 10:54:04 +02:00
|
|
|
|
expect(page).to have_text("Demandeur : #{avis_1.claimant.email}")
|
2023-03-17 11:30:20 +01:00
|
|
|
|
click_on 'Voir les avis'
|
2021-05-25 10:54:04 +02:00
|
|
|
|
expect(page).to have_text("Vous")
|
|
|
|
|
expect(page).to have_text(avis_2.expert.email.to_s)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'As a expert_2, I cannot read expert_1 advice because it is confidential' do
|
|
|
|
|
login_as expert_2.user, scope: :user
|
|
|
|
|
|
|
|
|
|
visit expert_all_avis_path
|
|
|
|
|
expect(page).to have_text('1 avis à donner')
|
|
|
|
|
expect(page).to have_text('0 avis donnés')
|
|
|
|
|
|
|
|
|
|
click_on '1 avis à donner'
|
|
|
|
|
click_on avis_2.dossier.user.email
|
2023-11-09 15:02:43 +01:00
|
|
|
|
within('.fr-tabs') { click_on 'Avis' }
|
2021-05-25 10:54:04 +02:00
|
|
|
|
expect(page).to have_text("Demandeur : #{avis_2.claimant.email}")
|
2023-03-17 11:30:20 +01:00
|
|
|
|
click_on 'Voir les avis'
|
2021-05-25 10:54:04 +02:00
|
|
|
|
expect(page).to have_text("Vous")
|
|
|
|
|
expect(page).not_to have_text(avis_1.expert.email.to_s)
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-02-28 22:20:24 +01:00
|
|
|
|
end
|