From c178e9226b32e25ac2107c33fb6fd636820223bb Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 16 Oct 2018 15:52:34 +0000 Subject: [PATCH] spec: add integration tests for the new SIRET flow --- .../new_user/dossier_creation_spec.rb | 30 ++++-- spec/features/users/complete_demande_spec.rb | 92 ------------------- spec/features/users/start_demande_spec.rb | 48 ---------- 3 files changed, 22 insertions(+), 148 deletions(-) delete mode 100644 spec/features/users/complete_demande_spec.rb delete mode 100644 spec/features/users/start_demande_spec.rb diff --git a/spec/features/new_user/dossier_creation_spec.rb b/spec/features/new_user/dossier_creation_spec.rb index 7b94d9696..6c468745a 100644 --- a/spec/features/new_user/dossier_creation_spec.rb +++ b/spec/features/new_user/dossier_creation_spec.rb @@ -62,6 +62,7 @@ feature 'Creating a new dossier:' do context 'when identifying through SIRET' do let(:procedure) { create(:procedure, :published, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) } + let(:dossier) { procedure.dossiers.last } before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/) @@ -76,18 +77,31 @@ feature 'Creating a new dossier:' do scenario 'the user can enter the SIRET of its etablissement and create a new draft', vcr: { cassette_name: 'api_adresse_search_paris_3' }, js: true do visit commencer_path(procedure_path: procedure.path) - dossier = procedure.dossiers.last expect(page).to have_current_path(siret_dossier_path(dossier)) - page.find_by_id('dossier-siret').set siret + fill_in 'Numéro SIRET', with: siret click_on 'Valider' - wait_for_ajax - expect(page).to have_css('#recap-info-entreprise') - click_on 'Etape suivante' - expect(page).to have_current_path(users_dossier_carte_path(procedure.dossiers.last.id.to_s)) - click_on 'Etape suivante' - expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last)) + expect(page).to have_current_path(etablissement_dossier_path(dossier)) + expect(page).to have_content('OCTO-TECHNOLOGY') + click_on 'Continuer avec ces informations' + + expect(page).to have_current_path(users_dossier_carte_path(dossier)) + click_button('Etape suivante') + + expect(page).to have_current_path(brouillon_dossier_path(dossier)) + end + + scenario 'the user is notified when its SIRET is invalid' do + visit commencer_path(procedure_path: procedure.path) + expect(page).to have_current_path(siret_dossier_path(dossier)) + + fill_in 'Numéro SIRET', with: '0000' + click_on 'Valider' + + expect(page).to have_current_path(siret_dossier_path(dossier)) + expect(page).to have_content('Le numéro SIRET doit comporter 14 chiffres') + expect(page).to have_field('Numéro SIRET', with: '0000') end end end diff --git a/spec/features/users/complete_demande_spec.rb b/spec/features/users/complete_demande_spec.rb deleted file mode 100644 index 725e5135f..000000000 --- a/spec/features/users/complete_demande_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -require 'spec_helper' - -feature 'user path for dossier creation' do - let(:user) { create(:user) } - let(:procedure) { create(:procedure, :published, :with_type_de_champ) } - let(:siret) { '53272417600013' } - let(:siren) { siret[0...9] } - - context 'user arrives on siret page', js: true do - before do - visit commencer_path(procedure_path: procedure.path) - end - - scenario 'he is redirected on login page' do - expect(page).to have_css('#new_user') - expect(page).to have_css('.procedure-logos') - expect(page).to have_content(procedure.libelle) - end - - context 'user sign_in' do - before do - within('#new_user') do - page.find_by_id('user_email').set user.email - page.find_by_id('user_password').set user.password - page.click_on 'Se connecter' - end - end - scenario 'redirects to siret page' do - expect(page).to have_css('#dossier-siret') - end - context 'sets siret' do - before do - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/) - .to_return(body: File.read('spec/fixtures/files/api_entreprise/etablissements.json', status: 200)) - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/) - .to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json')) - - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/#{siret}?.*token=/) - .to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/exercices.json')) - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/) - .to_return(status: 404, body: '') - - page.find_by_id('dossier-siret').set siret - page.click_on 'Valider' - end - - scenario 'user is on page recap info entreprise' do - expect(page).to have_css('#recap-info-entreprise') - end - - context 'when user would like change siret' do - before do - page.click_on('Changer de SIRET') - end - - scenario 'redirects to siret page' do - expect(page).to have_css('#dossier-siret') - end - end - - context 'when validating info entreprise recap page' do - before do - page.find_by_id('etape_suivante').click - end - scenario 'user is on edition page' do - expect(page).to have_current_path(brouillon_dossier_path(Dossier.last)) - end - context 'user fill and validate description page' do - before do - page.find_by_id("dossier_champs_attributes_0_value").set 'Mon super projet' - click_on 'Soumettre le dossier' - end - scenario 'user is on merci page' do - expect(page).to have_current_path(merci_dossier_path(Dossier.last)) - end - end - end - end - end - end - - context 'user cannot access non-published procedures' do - let(:procedure) { create(:procedure) } - before do - visit new_users_dossiers_path(procedure_id: procedure.id) - end - - scenario 'user is on home page', vcr: { cassette_name: 'complete_demande_spec' } do - expect(page).to have_content('La démarche n\'existe pas') - end - end -end diff --git a/spec/features/users/start_demande_spec.rb b/spec/features/users/start_demande_spec.rb deleted file mode 100644 index 5cd48a6b4..000000000 --- a/spec/features/users/start_demande_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'spec_helper' - -feature 'user arrive on siret page' do - let(:procedure) { create(:procedure, :published) } - let(:user) { create(:user) } - let(:siret) { '42149333900020' } - let(:siren) { siret[0...9] } - - context 'when user is not logged in' do - before do - visit new_users_dossiers_path(procedure_id: procedure.id) - end - scenario 'he is redirected to login page' do - expect(page).to have_css('#new_user') - end - context 'when he enter login information' do - before do - within('#new_user') do - page.find_by_id('user_email').set user.email - page.find_by_id('user_password').set user.password - page.click_on 'Se connecter' - end - end - scenario 'he is redirected to siret page to enter a siret' do - expect(page).to have_css('#new_siret') - end - context 'when enter a siret', js: true do - before do - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/) - .to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json')) - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/) - .to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json')) - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/#{siret}?.*token=/) - .to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/exercices.json')) - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/) - .to_return(status: 404, body: '') - - page.find_by_id('dossier-siret').set siret - page.click_on 'Valider' - end - scenario 'he is redirected to recap info entreprise page' do - wait_for_ajax - expect(page).to have_css('#recap-info-entreprise') - end - end - end - end -end