2023-11-06 15:15:51 +01:00
|
|
|
|
describe 'Prefilling a dossier (with a GET request):', js: true do
|
2023-03-03 14:16:15 +01:00
|
|
|
|
let(:password) { SECURE_PASSWORD }
|
2023-01-03 14:46:10 +01:00
|
|
|
|
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:types_de_champ_public) do
|
|
|
|
|
[
|
|
|
|
|
{ type: :text },
|
|
|
|
|
{ type: :phone },
|
|
|
|
|
{ type: :rna },
|
|
|
|
|
{ type: :siret },
|
|
|
|
|
{ type: :datetime },
|
|
|
|
|
{ type: :multiple_drop_down_list },
|
|
|
|
|
{ type: :epci },
|
|
|
|
|
{ type: :annuaire_education },
|
|
|
|
|
{ type: :dossier_link },
|
|
|
|
|
{ type: :communes },
|
|
|
|
|
{ type: :address },
|
|
|
|
|
{ type: :repetition, children: [{ type: :text }, { type: :decimal_number }] }
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
let(:procedure) { create(:procedure, :for_individual, :published, opendata: true, types_de_champ_public:) }
|
2023-01-03 14:46:10 +01:00
|
|
|
|
let(:dossier) { procedure.dossiers.last }
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:types_de_champ) { procedure.active_revision.types_de_champ_public }
|
|
|
|
|
|
|
|
|
|
let(:type_de_champ_text) { types_de_champ[0] }
|
|
|
|
|
let(:type_de_champ_phone) { types_de_champ[1] }
|
|
|
|
|
let(:type_de_champ_rna) { types_de_champ[2] }
|
|
|
|
|
let(:type_de_champ_siret) { types_de_champ[3] }
|
|
|
|
|
let(:type_de_champ_datetime) { types_de_champ[4] }
|
|
|
|
|
let(:type_de_champ_multiple_drop_down_list) { types_de_champ[5] }
|
|
|
|
|
let(:type_de_champ_epci) { types_de_champ[6] }
|
|
|
|
|
let(:type_de_champ_annuaire_education) { types_de_champ[7] }
|
|
|
|
|
let(:type_de_champ_dossier_link) { types_de_champ[8] }
|
|
|
|
|
let(:type_de_champ_commune) { types_de_champ[9] }
|
|
|
|
|
let(:type_de_champ_address) { types_de_champ[10] }
|
|
|
|
|
let(:type_de_champ_repetition) { types_de_champ[11] }
|
2023-01-25 12:05:00 +01:00
|
|
|
|
|
2023-01-03 14:46:10 +01:00
|
|
|
|
let(:text_value) { "My Neighbor Totoro is the best movie ever" }
|
|
|
|
|
let(:phone_value) { "invalid phone value" }
|
2023-01-26 10:33:08 +01:00
|
|
|
|
let(:rna_value) { 'W595001988' }
|
2023-01-25 12:05:00 +01:00
|
|
|
|
let(:siret_value) { '41816609600051' }
|
2023-02-09 15:18:38 +01:00
|
|
|
|
let(:datetime_value) { "2023-02-01T10:32" }
|
2023-01-24 11:44:02 +01:00
|
|
|
|
let(:multiple_drop_down_list_values) {
|
|
|
|
|
[
|
|
|
|
|
type_de_champ_multiple_drop_down_list.drop_down_list_enabled_non_empty_options.first,
|
|
|
|
|
type_de_champ_multiple_drop_down_list.drop_down_list_enabled_non_empty_options.last
|
|
|
|
|
]
|
|
|
|
|
}
|
2023-02-06 15:12:34 +01:00
|
|
|
|
let(:epci_value) { ['01', '200029999'] }
|
2023-02-22 16:05:44 +01:00
|
|
|
|
let(:dossier_link_value) { '42' }
|
2023-10-13 16:06:26 +02:00
|
|
|
|
let(:commune_value) { ['01540', '01457'] }
|
2023-03-21 14:47:14 +01:00
|
|
|
|
let(:commune_libelle) { 'Vonnas (01540)' }
|
2023-02-28 09:48:26 +01:00
|
|
|
|
let(:address_value) { "20 Avenue de Ségur 75007 Paris" }
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:sub_types_de_champ_repetition) { procedure.active_revision.children_of(type_de_champ_repetition) }
|
|
|
|
|
let(:text_repetition_libelle) { sub_types_de_champ_repetition.first.libelle }
|
|
|
|
|
let(:integer_repetition_libelle) { sub_types_de_champ_repetition.second.libelle }
|
2023-02-03 12:14:18 +01:00
|
|
|
|
let(:text_repetition_value) { "First repetition text" }
|
|
|
|
|
let(:integer_repetition_value) { "42" }
|
2023-02-16 14:26:05 +01:00
|
|
|
|
let(:annuaire_education_value) { '0050009H' }
|
2023-09-07 10:10:07 +02:00
|
|
|
|
let(:prenom_value) { 'Jean' }
|
|
|
|
|
let(:nom_value) { 'Dupont' }
|
|
|
|
|
let(:genre_value) { 'M.' }
|
2023-02-15 17:39:19 +01:00
|
|
|
|
|
2023-01-24 11:44:02 +01:00
|
|
|
|
let(:entry_path) {
|
|
|
|
|
commencer_path(
|
|
|
|
|
path: procedure.path,
|
2023-02-22 19:32:25 +01:00
|
|
|
|
"champ_#{type_de_champ_text.to_typed_id_for_query}" => text_value,
|
|
|
|
|
"champ_#{type_de_champ_phone.to_typed_id_for_query}" => phone_value,
|
|
|
|
|
"champ_#{type_de_champ_datetime.to_typed_id_for_query}" => datetime_value,
|
|
|
|
|
"champ_#{type_de_champ_multiple_drop_down_list.to_typed_id_for_query}" => multiple_drop_down_list_values,
|
|
|
|
|
"champ_#{type_de_champ_epci.to_typed_id_for_query}" => epci_value,
|
2023-02-22 16:05:44 +01:00
|
|
|
|
"champ_#{type_de_champ_dossier_link.to_typed_id_for_query}" => dossier_link_value,
|
2023-02-24 10:49:11 +01:00
|
|
|
|
"champ_#{type_de_champ_commune.to_typed_id_for_query}" => commune_value,
|
2023-02-28 09:48:26 +01:00
|
|
|
|
"champ_#{type_de_champ_address.to_typed_id_for_query}" => address_value,
|
2023-01-25 12:05:00 +01:00
|
|
|
|
"champ_#{type_de_champ_siret.to_typed_id_for_query}" => siret_value,
|
2023-01-26 10:33:08 +01:00
|
|
|
|
"champ_#{type_de_champ_rna.to_typed_id_for_query}" => rna_value,
|
2023-02-22 19:32:25 +01:00
|
|
|
|
"champ_#{type_de_champ_repetition.to_typed_id_for_query}" => [
|
|
|
|
|
{
|
2024-07-01 15:31:32 +02:00
|
|
|
|
"champ_#{sub_types_de_champ_repetition.first.to_typed_id_for_query}": text_repetition_value,
|
|
|
|
|
"champ_#{sub_types_de_champ_repetition.second.to_typed_id_for_query}": integer_repetition_value
|
2023-02-22 19:32:25 +01:00
|
|
|
|
}
|
2023-02-16 14:26:05 +01:00
|
|
|
|
],
|
2023-09-07 10:10:07 +02:00
|
|
|
|
"champ_#{type_de_champ_annuaire_education.to_typed_id_for_query}" => annuaire_education_value,
|
|
|
|
|
"identite_prenom" => prenom_value,
|
|
|
|
|
"identite_nom" => nom_value,
|
|
|
|
|
"identite_genre" => genre_value
|
2023-01-24 11:44:02 +01:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 17:39:19 +01:00
|
|
|
|
before do
|
2023-05-30 16:27:20 +02:00
|
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\//)
|
2023-01-25 12:05:00 +01: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\/#{siret_value[0..8]}/)
|
2023-02-02 09:59:59 +01:00
|
|
|
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
|
|
|
|
|
2023-05-30 11:32:59 +02:00
|
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v4\/djepva\/api-association\/associations\/open_data\/#{rna_value}/)
|
2023-01-26 10:33:08 +01:00
|
|
|
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/associations.json'))
|
2023-02-15 17:39:19 +01:00
|
|
|
|
end
|
2023-01-03 14:46:10 +01:00
|
|
|
|
|
|
|
|
|
context 'when authenticated' do
|
|
|
|
|
it_behaves_like "the user has got a prefilled dossier, owned by themselves" do
|
|
|
|
|
let(:user) { create(:user, password: password) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
visit "/users/sign_in"
|
|
|
|
|
sign_in_with user.email, password
|
2023-01-24 11:44:02 +01:00
|
|
|
|
visit entry_path
|
2023-01-03 14:46:10 +01:00
|
|
|
|
|
2023-02-08 15:06:45 +01:00
|
|
|
|
click_on "Poursuivre mon dossier prérempli"
|
2023-01-03 14:46:10 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-01 10:21:22 +01:00
|
|
|
|
context 'when authenticated with existing dossier and session params (ie: reload the page)' do
|
|
|
|
|
let(:user) { create(:user, password: password) }
|
2024-07-01 15:31:32 +02:00
|
|
|
|
let(:dossier) { create(:dossier, :prefilled, procedure:, prefill_token: "token", user: nil) }
|
|
|
|
|
let(:types_de_champ_public) { [{}] }
|
2023-03-01 10:21:22 +01:00
|
|
|
|
|
|
|
|
|
before do
|
2024-07-01 15:31:32 +02:00
|
|
|
|
dossier.champs.first.update(value: text_value)
|
2023-03-01 10:21:22 +01:00
|
|
|
|
page.set_rack_session(prefill_token: "token")
|
2023-09-07 10:10:07 +02:00
|
|
|
|
page.set_rack_session(prefill_params_digest: PrefillChamps.digest({ "champ_#{type_de_champ_text.to_typed_id}" => text_value }))
|
2023-03-01 10:21:22 +01:00
|
|
|
|
|
|
|
|
|
visit "/users/sign_in"
|
|
|
|
|
sign_in_with user.email, password
|
|
|
|
|
|
|
|
|
|
visit commencer_path(
|
|
|
|
|
path: procedure.path,
|
|
|
|
|
"champ_#{type_de_champ_text.to_typed_id}" => text_value
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
click_on "Poursuivre mon dossier prérempli"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should not create a new dossier" do
|
|
|
|
|
expect(Dossier.count).to eq(1)
|
|
|
|
|
expect(dossier.reload.user).to eq(user)
|
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
|
|
|
|
expect(page).to have_field(type_de_champ_text.libelle, with: text_value)
|
|
|
|
|
|
|
|
|
|
expect(page.get_rack_session[:prefill_token]).to be_nil
|
2023-06-12 12:05:48 +02:00
|
|
|
|
expect(page.get_rack_session[:prefill_params_digest]).to be_nil
|
2023-03-01 10:21:22 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-03 14:46:10 +01:00
|
|
|
|
context 'when unauthenticated' do
|
2023-01-24 11:44:02 +01:00
|
|
|
|
before { visit entry_path }
|
2023-01-03 14:46:10 +01:00
|
|
|
|
|
|
|
|
|
context 'when the user signs in with email and password' do
|
|
|
|
|
it_behaves_like "the user has got a prefilled dossier, owned by themselves" do
|
|
|
|
|
let!(:user) { create(:user, password: password) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
click_on "J’ai déjà un compte"
|
|
|
|
|
sign_in_with user.email, password
|
|
|
|
|
|
2023-02-08 15:06:45 +01:00
|
|
|
|
click_on "Poursuivre mon dossier prérempli"
|
2023-01-03 14:46:10 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the user signs up with email and password' do
|
|
|
|
|
it_behaves_like "the user has got a prefilled dossier, owned by themselves" do
|
|
|
|
|
let(:user_email) { generate :user_email }
|
|
|
|
|
let(:user) { User.find_by(email: user_email) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
click_on "Créer un compte #{APPLICATION_NAME}"
|
|
|
|
|
|
|
|
|
|
sign_up_with user_email, password
|
2024-02-20 14:28:45 +01:00
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse électronique #{user_email}"
|
2023-01-03 14:46:10 +01:00
|
|
|
|
|
|
|
|
|
click_confirmation_link_for user_email
|
|
|
|
|
expect(page).to have_content('Votre compte a bien été confirmé.')
|
|
|
|
|
|
2023-02-08 15:06:45 +01:00
|
|
|
|
click_on "Poursuivre mon dossier prérempli"
|
2023-01-03 14:46:10 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the user signs up with FranceConnect' do
|
|
|
|
|
it_behaves_like "the user has got a prefilled dossier, owned by themselves" do
|
|
|
|
|
let(:user) { User.last }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: "c0d3"))
|
|
|
|
|
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(build(:france_connect_information))
|
|
|
|
|
|
|
|
|
|
page.find('.fr-connect').click
|
|
|
|
|
|
2023-02-08 15:06:45 +01:00
|
|
|
|
click_on "Poursuivre mon dossier prérempli"
|
2023-01-03 14:46:10 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|