cover use case with a feature spec

This commit is contained in:
sebastiencarceles 2023-01-25 12:05:00 +01:00
parent 5dce401a14
commit 498e5d7487
3 changed files with 18 additions and 7 deletions

View file

@ -1,13 +1,9 @@
shared_examples "the user has got a prefilled dossier, owned by themselves" do shared_examples "the user has got a prefilled dossier, owned by themselves" do
scenario "the user has got a prefilled dossier, owned by themselves" do scenario "the user has got a prefilled dossier, owned by themselves" do
siret = '41816609600051'
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
expect(dossier.user).to eq(user) expect(dossier.user).to eq(user)
expect(page).to have_current_path siret_dossier_path(procedure.dossiers.last) expect(page).to have_current_path siret_dossier_path(procedure.dossiers.last)
fill_in 'Numéro SIRET', with: siret fill_in 'Numéro SIRET', with: siret_value
click_on 'Valider' click_on 'Valider'
expect(page).to have_current_path(etablissement_dossier_path(dossier)) expect(page).to have_current_path(etablissement_dossier_path(dossier))
@ -18,6 +14,7 @@ shared_examples "the user has got a prefilled dossier, owned by themselves" do
expect(page).to have_field(type_de_champ_text.libelle, with: text_value) expect(page).to have_field(type_de_champ_text.libelle, with: text_value)
expect(page).to have_field(type_de_champ_phone.libelle, with: phone_value) expect(page).to have_field(type_de_champ_phone.libelle, with: phone_value)
expect(page).to have_css('label', text: type_de_champ_phone.libelle) expect(page).to have_css('label', text: type_de_champ_phone.libelle)
expect(page).to have_field(type_de_champ_siret.libelle, with: siret_value)
expect(page).to have_css('h3', text: type_de_champ_repetition.libelle) expect(page).to have_css('h3', text: type_de_champ_repetition.libelle)
expect(page).to have_field(text_repetition_libelle, with: text_repetition_value) expect(page).to have_field(text_repetition_libelle, with: text_repetition_value)
expect(page).to have_field(integer_repetition_libelle, with: integer_repetition_value) expect(page).to have_field(integer_repetition_libelle, with: integer_repetition_value)

View file

@ -1,4 +1,4 @@
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(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
let(:password) { 'my-s3cure-p4ssword' } let(:password) { 'my-s3cure-p4ssword' }
@ -8,13 +8,16 @@ 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_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_phone) { create(:type_de_champ_phone, procedure: procedure) } let(:type_de_champ_phone) { create(:type_de_champ_phone, 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_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_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_epci) { create(:type_de_champ_epci, procedure: procedure) }
let(:type_de_champ_commune) { create(:type_de_champ_communes, 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(: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(:text_value) { "My Neighbor Totoro is the best movie ever" }
let(:phone_value) { "invalid phone value" } let(:phone_value) { "invalid phone value" }
let(:siret_value) { '41816609600051' }
let(:datetime_value) { "2023-02-01T10:32" } let(:datetime_value) { "2023-02-01T10:32" }
let(:multiple_drop_down_list_values) { let(:multiple_drop_down_list_values) {
[ [
@ -39,6 +42,7 @@ describe 'Prefilling a dossier (with a GET request):' do
"champ_#{type_de_champ_multiple_drop_down_list.to_typed_id_for_query}" => multiple_drop_down_list_values, "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_epci.to_typed_id_for_query}" => epci_value,
"champ_#{type_de_champ_commune.to_typed_id_for_query}" => commune_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_repetition.to_typed_id_for_query}" => [ "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.first.to_typed_id_for_query}": text_repetition_value,
@ -52,6 +56,9 @@ describe 'Prefilling a dossier (with a GET request):' do
allow(Rails).to receive(:cache).and_return(memory_store) allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear 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'))
VCR.insert_cassette('api_geo_departements') VCR.insert_cassette('api_geo_departements')
VCR.insert_cassette('api_geo_communes') VCR.insert_cassette('api_geo_communes')
VCR.insert_cassette('api_geo_epcis') VCR.insert_cassette('api_geo_epcis')

View file

@ -1,4 +1,4 @@
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(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
let(:password) { 'my-s3cure-p4ssword' } let(:password) { 'my-s3cure-p4ssword' }
@ -8,13 +8,16 @@ 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_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_phone) { create(:type_de_champ_phone, procedure: procedure) } let(:type_de_champ_phone) { create(:type_de_champ_phone, 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_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_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_epci) { create(:type_de_champ_epci, procedure: procedure) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, 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(:type_de_champ_commune) { create(:type_de_champ_communes, procedure: procedure) }
let(:text_value) { "My Neighbor Totoro is the best movie ever" } let(:text_value) { "My Neighbor Totoro is the best movie ever" }
let(:phone_value) { "invalid phone value" } let(:phone_value) { "invalid phone value" }
let(:siret_value) { '41816609600051' }
let(:datetime_value) { "2023-02-01T10:32" } let(:datetime_value) { "2023-02-01T10:32" }
let(:multiple_drop_down_list_values) { let(:multiple_drop_down_list_values) {
[ [
@ -34,6 +37,9 @@ describe 'Prefilling a dossier (with a POST request):' do
allow(Rails).to receive(:cache).and_return(memory_store) allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear 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'))
VCR.insert_cassette('api_geo_departements') VCR.insert_cassette('api_geo_departements')
VCR.insert_cassette('api_geo_communes') VCR.insert_cassette('api_geo_communes')
VCR.insert_cassette('api_geo_epcis') VCR.insert_cassette('api_geo_epcis')
@ -132,6 +138,7 @@ describe 'Prefilling a dossier (with a POST request):' do
params: { params: {
"champ_#{type_de_champ_text.to_typed_id_for_query}" => text_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_phone.to_typed_id_for_query}" => phone_value,
"champ_#{type_de_champ_siret.to_typed_id_for_query}" => siret_value,
"champ_#{type_de_champ_repetition.to_typed_id_for_query}" => [ "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.first.to_typed_id_for_query}": text_repetition_value,