2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
describe 'Creating a new dossier:', js: true do
|
2016-12-19 17:15:59 +01:00
|
|
|
|
let(:user) { create(:user) }
|
2020-04-07 19:29:14 +02:00
|
|
|
|
let(:siret) { '41816609600051' }
|
2016-12-19 17:15:59 +01:00
|
|
|
|
let(:siren) { siret[0...9] }
|
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
|
context 'when the user is already signed in' do
|
|
|
|
|
before do
|
|
|
|
|
login_as user, scope: :user
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the procedure has identification by individual' do
|
2022-11-24 14:04:33 +01:00
|
|
|
|
let(:libelle) { "[title] with characters to escape : '@*^$" }
|
|
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, ask_birthday: ask_birthday, libelle: libelle) }
|
2018-10-15 15:46:23 +02:00
|
|
|
|
let(:ask_birthday) { false }
|
|
|
|
|
let(:expected_birthday) { nil }
|
2016-12-19 17:15:59 +01:00
|
|
|
|
|
2017-03-28 18:06:49 +02:00
|
|
|
|
before do
|
2018-10-30 12:00:58 +01:00
|
|
|
|
visit commencer_path(path: procedure.path)
|
2019-01-16 11:57:58 +01:00
|
|
|
|
click_on 'Commencer la démarche'
|
2019-01-07 12:17:11 +01:00
|
|
|
|
|
2019-01-16 11:57:58 +01:00
|
|
|
|
expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last)
|
2022-11-24 14:04:33 +01:00
|
|
|
|
expect(page).to have_title(libelle)
|
2019-01-07 12:17:11 +01:00
|
|
|
|
|
2023-09-05 14:42:56 +02:00
|
|
|
|
find('label', text: 'Monsieur').click
|
2023-11-28 12:43:43 +01:00
|
|
|
|
fill_in('Prénom', with: 'prenom', visible: true)
|
|
|
|
|
fill_in('Nom', with: 'nom', visible: true)
|
2017-03-28 18:06:49 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
|
shared_examples 'the user can create a new draft' do
|
|
|
|
|
it do
|
2024-04-12 17:59:50 +02:00
|
|
|
|
within "#identite-form" do
|
|
|
|
|
click_button('Continuer')
|
|
|
|
|
end
|
2018-02-12 15:55:51 +01:00
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last))
|
|
|
|
|
expect(user.dossiers.first.individual.birthdate).to eq(expected_birthday)
|
2018-02-06 16:58:04 +01:00
|
|
|
|
end
|
2018-10-15 15:46:23 +02:00
|
|
|
|
end
|
2018-02-06 16:58:04 +01:00
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
|
context 'when the birthday is asked' do
|
|
|
|
|
let(:ask_birthday) { true }
|
2023-11-28 12:43:43 +01:00
|
|
|
|
let(:expected_birthday) { Date.new(1987, 12, 10) }
|
2018-02-12 15:55:51 +01:00
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
|
before do
|
2023-09-18 18:15:28 +02:00
|
|
|
|
fill_in 'Date de naissance', with: birthday_format
|
2018-10-15 15:46:23 +02:00
|
|
|
|
end
|
2018-02-12 15:55:51 +01:00
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
context 'when the birthday is asked' do
|
|
|
|
|
let(:birthday_format) { '12-10-1987' }
|
2018-10-15 15:46:23 +02:00
|
|
|
|
it_behaves_like 'the user can create a new draft'
|
2018-02-06 16:58:04 +01:00
|
|
|
|
end
|
2017-03-28 18:06:49 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
|
context 'when the birthday is not asked' do
|
2018-02-06 16:58:04 +01:00
|
|
|
|
let(:ask_birthday) { false }
|
2018-10-15 15:46:23 +02:00
|
|
|
|
let(:expected_birthday) { nil }
|
|
|
|
|
it_behaves_like 'the user can create a new draft'
|
|
|
|
|
end
|
2018-02-06 16:58:04 +01:00
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
context 'when individual fill dossier for a tiers' do
|
|
|
|
|
it 'completes the form with email notification method selected' do
|
2024-02-05 11:51:36 +01:00
|
|
|
|
find('label', text: 'Pour un bénéficiaire : membre de la famille, proche, mandant, professionnel en charge du suivi du dossier…').click
|
2023-11-28 12:43:43 +01:00
|
|
|
|
within('.mandataire-infos') do
|
|
|
|
|
fill_in('Prénom', with: 'John')
|
|
|
|
|
fill_in('Nom', with: 'Doe')
|
|
|
|
|
end
|
2023-11-27 15:52:55 +01:00
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
find('label', text: 'Monsieur').click
|
2023-11-27 15:52:55 +01:00
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
within('.individual-infos') do
|
|
|
|
|
fill_in('Prénom', with: 'prenom')
|
|
|
|
|
fill_in('Nom', with: 'nom')
|
|
|
|
|
end
|
2023-11-27 15:52:55 +01:00
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
find('label', text: 'Par e-mail').click
|
|
|
|
|
fill_in('dossier_individual_attributes_email', with: 'prenom.nom@mail.com')
|
2024-04-12 17:59:50 +02:00
|
|
|
|
find('label', text: 'Monsieur').click # force focus out
|
|
|
|
|
within "#identite-form" do
|
|
|
|
|
within '.suspect-email' do
|
2024-07-30 10:02:23 +02:00
|
|
|
|
expect(page).to have_content("L'adresse semble erronée Vouliez-vous écrire : prenom.nom@gmail.com ? Oui Non")
|
2024-04-12 17:59:50 +02:00
|
|
|
|
click_button("Oui")
|
|
|
|
|
end
|
|
|
|
|
click_button("Continuer")
|
|
|
|
|
end
|
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
expect(procedure.dossiers.last.individual.notification_method == 'email')
|
|
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last))
|
|
|
|
|
end
|
2023-11-27 15:52:55 +01:00
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
it 'completes the form with no notification method selected' do
|
2024-02-05 11:51:36 +01:00
|
|
|
|
find('label', text: 'Pour un bénéficiaire : membre de la famille, proche, mandant, professionnel en charge du suivi du dossier…').click
|
2023-11-28 12:43:43 +01:00
|
|
|
|
|
|
|
|
|
within('.mandataire-infos') do
|
|
|
|
|
fill_in('Prénom', with: 'John')
|
|
|
|
|
fill_in('Nom', with: 'Doe')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
find('label', text: 'Monsieur').click
|
|
|
|
|
within('.individual-infos') do
|
|
|
|
|
fill_in('Prénom', with: 'prenom')
|
|
|
|
|
fill_in('Nom', with: 'nom')
|
|
|
|
|
end
|
2023-11-27 15:52:55 +01:00
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
find('label', text: 'Pas de notification').click
|
2024-04-12 17:59:50 +02:00
|
|
|
|
within "#identite-form" do
|
|
|
|
|
click_button('Continuer')
|
|
|
|
|
end
|
|
|
|
|
|
2023-11-28 12:43:43 +01:00
|
|
|
|
expect(procedure.dossiers.last.individual.notification_method.empty?)
|
|
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last))
|
|
|
|
|
end
|
2023-11-27 15:52:55 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
|
context 'when identifying through SIRET' do
|
2019-07-25 15:57:00 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ) }
|
2018-10-16 17:52:34 +02:00
|
|
|
|
let(:dossier) { procedure.dossiers.last }
|
2018-02-12 15:55:51 +01:00
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
|
before do
|
2023-05-30 16:27:20 +02:00
|
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}/)
|
2018-10-15 15:46:23 +02:00
|
|
|
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
2023-05-25 11:15:26 +02:00
|
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
2018-10-15 15:46:23 +02:00
|
|
|
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
2020-12-10 15:28:39 +01:00
|
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/#{siret}/)
|
2018-10-15 15:46:23 +02:00
|
|
|
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/exercices.json'))
|
2020-12-10 15:28:39 +01:00
|
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}/)
|
2018-10-15 15:46:23 +02:00
|
|
|
|
.to_return(status: 404, body: '')
|
2020-12-10 15:28:39 +01:00
|
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/2020\/02\/entreprise\/#{siren}/)
|
2020-04-07 19:29:14 +02:00
|
|
|
|
.to_return(status: 404, body: '')
|
2020-12-10 15:28:39 +01:00
|
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/)
|
2020-04-22 17:53:45 +02:00
|
|
|
|
.to_return(status: 404, body: '')
|
2020-08-05 18:40:47 +02:00
|
|
|
|
allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return([])
|
|
|
|
|
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
2018-10-15 15:46:23 +02:00
|
|
|
|
end
|
2020-04-07 19:29:14 +02:00
|
|
|
|
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
|
|
|
|
after { Timecop.return }
|
2018-02-12 15:55:51 +01:00
|
|
|
|
|
2020-01-14 18:46:07 +01:00
|
|
|
|
scenario 'the user can enter the SIRET of its etablissement and create a new draft' do
|
2018-10-30 12:00:58 +01:00
|
|
|
|
visit commencer_path(path: procedure.path)
|
2019-01-16 11:57:58 +01:00
|
|
|
|
click_on 'Commencer la démarche'
|
2019-01-07 12:17:11 +01:00
|
|
|
|
|
2019-01-16 11:57:58 +01:00
|
|
|
|
expect(page).to have_current_path siret_dossier_path(dossier)
|
2023-05-25 16:49:07 +02:00
|
|
|
|
expect(page).to have_content(procedure.libelle)
|
2018-02-12 15:55:51 +01:00
|
|
|
|
|
2018-10-16 17:52:34 +02:00
|
|
|
|
fill_in 'Numéro SIRET', with: siret
|
2023-09-18 15:24:06 +02:00
|
|
|
|
click_on 'Continuer'
|
2016-12-19 17:15:59 +01:00
|
|
|
|
|
2018-10-16 17:52:34 +02:00
|
|
|
|
expect(page).to have_current_path(etablissement_dossier_path(dossier))
|
2023-05-30 16:27:20 +02:00
|
|
|
|
expect(page).to have_content('Coiff Land, CoiffureLand')
|
2018-10-16 17:52:34 +02:00
|
|
|
|
click_on 'Continuer avec ces informations'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'the user is notified when its SIRET is invalid' do
|
2018-10-30 12:00:58 +01:00
|
|
|
|
visit commencer_path(path: procedure.path)
|
2019-01-16 11:57:58 +01:00
|
|
|
|
click_on 'Commencer la démarche'
|
|
|
|
|
|
2018-10-16 17:52:34 +02:00
|
|
|
|
expect(page).to have_current_path(siret_dossier_path(dossier))
|
2023-05-25 16:49:07 +02:00
|
|
|
|
expect(page).to have_content(procedure.libelle)
|
2018-10-16 17:52:34 +02:00
|
|
|
|
|
|
|
|
|
fill_in 'Numéro SIRET', with: '0000'
|
2023-09-18 15:24:06 +02:00
|
|
|
|
click_on 'Continuer'
|
2018-10-16 17:52:34 +02:00
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path(siret_dossier_path(dossier))
|
2022-12-20 17:51:36 +01:00
|
|
|
|
expect(page).to have_content('Le champ « Siret » est invalide. Saisir un numéro SIRET avec 14 chiffres')
|
2018-10-16 17:52:34 +02:00
|
|
|
|
expect(page).to have_field('Numéro SIRET', with: '0000')
|
2018-10-15 15:46:23 +02:00
|
|
|
|
end
|
2016-12-19 17:15:59 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-03-18 16:29:48 +01:00
|
|
|
|
|
|
|
|
|
context 'when the user is not signed in' do
|
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
|
let(:procedure) { create(:procedure, :published) }
|
|
|
|
|
scenario 'the user is an instructeur with untrusted device' do
|
|
|
|
|
visit commencer_path(path: procedure.path)
|
|
|
|
|
click_on "J’ai déjà un compte"
|
|
|
|
|
sign_in_with(instructeur.email, instructeur.user.password, true)
|
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path(commencer_path(path: procedure.path))
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-12-19 17:15:59 +01:00
|
|
|
|
end
|