Merge branch 'main' into fix/stored_query_issue

This commit is contained in:
Damien Le Thiec 2023-03-01 10:22:40 +01:00 committed by GitHub
commit 8a7cb3f1fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
301 changed files with 4456 additions and 1168 deletions

View file

@ -1,4 +1,6 @@
describe 'Prefilling a dossier (with a GET request):' do
describe 'Prefilling a dossier (with a GET request):', js: true do
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
let(:password) { 'my-s3cure-p4ssword' }
let(:procedure) { create(:procedure, :published, opendata: true) }
@ -6,10 +8,82 @@ describe 'Prefilling a dossier (with a GET request):' do
let(:type_de_champ_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_phone) { create(:type_de_champ_phone, procedure: procedure) }
let(:type_de_champ_rna) { create(:type_de_champ_rna, procedure: procedure) }
let(:type_de_champ_siret) { create(:type_de_champ_siret, procedure: procedure) }
let(:type_de_champ_datetime) { create(:type_de_champ_datetime, procedure: procedure) }
let(:type_de_champ_multiple_drop_down_list) { create(:type_de_champ_multiple_drop_down_list, procedure: procedure) }
let(:type_de_champ_epci) { create(:type_de_champ_epci, procedure: procedure) }
let(:type_de_champ_annuaire_education) { create(:type_de_champ_annuaire_education, procedure: procedure) }
let(:type_de_champ_dossier_link) { create(:type_de_champ_dossier_link, procedure: procedure) }
let(:type_de_champ_commune) { create(:type_de_champ_communes, procedure: procedure) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
let(:text_value) { "My Neighbor Totoro is the best movie ever" }
let(:phone_value) { "invalid phone value" }
let(:rna_value) { 'W595001988' }
let(:siret_value) { '41816609600051' }
let(:datetime_value) { "2023-02-01T10:32" }
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
]
}
let(:epci_value) { ['01', '200029999'] }
let(:dossier_link_value) { '42' }
let(:commune_value) { ['01', '01457'] } # Vonnas (01540)
let(:sub_type_de_champs_repetition) { procedure.active_revision.children_of(type_de_champ_repetition) }
let(:text_repetition_libelle) { sub_type_de_champs_repetition.first.libelle }
let(:integer_repetition_libelle) { sub_type_de_champs_repetition.second.libelle }
let(:text_repetition_value) { "First repetition text" }
let(:integer_repetition_value) { "42" }
let(:annuaire_education_value) { '0050009H' }
let(:entry_path) {
commencer_path(
path: procedure.path,
"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,
"champ_#{type_de_champ_dossier_link.to_typed_id_for_query}" => dossier_link_value,
"champ_#{type_de_champ_commune.to_typed_id_for_query}" => commune_value,
"champ_#{type_de_champ_siret.to_typed_id_for_query}" => siret_value,
"champ_#{type_de_champ_rna.to_typed_id_for_query}" => rna_value,
"champ_#{type_de_champ_repetition.to_typed_id_for_query}" => [
{
"champ_#{sub_type_de_champs_repetition.first.to_typed_id_for_query}": text_repetition_value,
"champ_#{sub_type_de_champs_repetition.second.to_typed_id_for_query}": integer_repetition_value
}
],
"champ_#{type_de_champ_annuaire_education.to_typed_id_for_query}" => annuaire_education_value
)
}
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\//)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siret_value[0..8]}/)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/associations.json'))
VCR.insert_cassette('api_geo_departements')
VCR.insert_cassette('api_geo_communes')
VCR.insert_cassette('api_geo_epcis')
end
after do
VCR.eject_cassette('api_geo_departements')
VCR.eject_cassette('api_geo_communes')
VCR.eject_cassette('api_geo_epcis')
end
context 'when authenticated' do
it_behaves_like "the user has got a prefilled dossier, owned by themselves" do
@ -18,13 +92,7 @@ describe 'Prefilling a dossier (with a GET request):' do
before do
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,
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_datetime.to_typed_id}" => datetime_value
)
visit entry_path
click_on "Poursuivre mon dossier prérempli"
end
@ -65,14 +133,7 @@ describe 'Prefilling a dossier (with a GET request):' do
end
context 'when unauthenticated' do
before do
visit commencer_path(
path: procedure.path,
"champ_#{type_de_champ_text.to_typed_id}" => text_value,
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_datetime.to_typed_id}" => datetime_value
)
end
before { visit entry_path }
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

View file

@ -1,4 +1,6 @@
describe 'Prefilling a dossier (with a POST request):' do
describe 'Prefilling a dossier (with a POST request):', js: true do
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
let(:password) { 'my-s3cure-p4ssword' }
let(:procedure) { create(:procedure, :published) }
@ -6,10 +8,60 @@ describe 'Prefilling a dossier (with a POST request):' do
let(:type_de_champ_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_phone) { create(:type_de_champ_phone, procedure: procedure) }
let(:type_de_champ_rna) { create(:type_de_champ_rna, procedure: procedure) }
let(:type_de_champ_siret) { create(:type_de_champ_siret, procedure: procedure) }
let(:type_de_champ_datetime) { create(:type_de_champ_datetime, procedure: procedure) }
let(:type_de_champ_multiple_drop_down_list) { create(:type_de_champ_multiple_drop_down_list, procedure: procedure) }
let(:type_de_champ_epci) { create(:type_de_champ_epci, procedure: procedure) }
let(:type_de_champ_annuaire_education) { create(:type_de_champ_annuaire_education, procedure: procedure) }
let(:type_de_champ_dossier_link) { create(:type_de_champ_dossier_link, procedure: procedure) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
let(:type_de_champ_commune) { create(:type_de_champ_communes, procedure: procedure) }
let(:text_value) { "My Neighbor Totoro is the best movie ever" }
let(:phone_value) { "invalid phone value" }
let(:rna_value) { 'W595001988' }
let(:siret_value) { '41816609600051' }
let(:datetime_value) { "2023-02-01T10:32" }
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
]
}
let(:epci_value) { ['01', '200029999'] }
let(:commune_value) { ['01', '01457'] } # Vonnas (01540)
let(:sub_type_de_champs_repetition) { procedure.active_revision.children_of(type_de_champ_repetition) }
let(:text_repetition_libelle) { sub_type_de_champs_repetition.first.libelle }
let(:integer_repetition_libelle) { sub_type_de_champs_repetition.second.libelle }
let(:text_repetition_value) { "First repetition text" }
let(:integer_repetition_value) { "42" }
let(:dossier_link_value) { '42' }
let(:annuaire_education_value) { '0050009H' }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret_value}/)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siret_value[0..8]}/)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/associations.json'))
VCR.insert_cassette('api_geo_departements')
VCR.insert_cassette('api_geo_communes')
VCR.insert_cassette('api_geo_epcis')
end
after do
VCR.eject_cassette('api_geo_departements')
VCR.eject_cassette('api_geo_communes')
VCR.eject_cassette('api_geo_epcis')
end
scenario "the user get the URL of a prefilled orphan brouillon dossier" do
dossier_url = create_and_prefill_dossier_with_post_request
@ -96,9 +148,22 @@ describe 'Prefilling a dossier (with a POST request):' do
session.post api_public_v1_dossiers_path(procedure),
headers: { "Content-Type" => "application/json" },
params: {
"champ_#{type_de_champ_text.to_typed_id}" => text_value,
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_datetime.to_typed_id}" => datetime_value
"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_rna.to_typed_id_for_query}" => rna_value,
"champ_#{type_de_champ_siret.to_typed_id_for_query}" => siret_value,
"champ_#{type_de_champ_repetition.to_typed_id_for_query}" => [
{
"champ_#{sub_type_de_champs_repetition.first.to_typed_id_for_query}": text_repetition_value,
"champ_#{sub_type_de_champs_repetition.second.to_typed_id_for_query}": integer_repetition_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,
"champ_#{type_de_champ_dossier_link.to_typed_id_for_query}" => dossier_link_value,
"champ_#{type_de_champ_commune.to_typed_id_for_query}" => commune_value,
"champ_#{type_de_champ_annuaire_education.to_typed_id_for_query}" => annuaire_education_value
}.to_json
JSON.parse(session.response.body)["dossier_url"].gsub("http://www.example.com", "")
end