spec: refactor dossier creation spec
This commit is contained in:
parent
879dfa0fcc
commit
015b74ae56
1 changed files with 66 additions and 61 deletions
|
@ -1,71 +1,69 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
feature 'As a User I wanna create a dossier' do
|
feature 'Creating a new dossier:' do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let(:siret) { '40307130100044' }
|
let(:siret) { '40307130100044' }
|
||||||
let(:siren) { siret[0...9] }
|
let(:siren) { siret[0...9] }
|
||||||
|
|
||||||
context 'Right after sign_in I shall see inscription by credentials/siret, I can create a new Dossier' do
|
context 'when the user is already signed in' do
|
||||||
let(:procedure_with_siret) { create(:procedure, :published, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) }
|
|
||||||
let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative, ask_birthday: ask_birthday) }
|
|
||||||
|
|
||||||
context 'Identification for individual' do
|
|
||||||
before do
|
before do
|
||||||
login_as user, scope: :user
|
login_as user, scope: :user
|
||||||
visit commencer_path(procedure_path: procedure_for_individual.path)
|
end
|
||||||
|
|
||||||
|
context 'when the procedure has identification by individual' do
|
||||||
|
let(:procedure) { create(:procedure, :published, :for_individual, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative, ask_birthday: ask_birthday) }
|
||||||
|
let(:ask_birthday) { false }
|
||||||
|
let(:expected_birthday) { nil }
|
||||||
|
|
||||||
|
before do
|
||||||
|
visit commencer_path(procedure_path: procedure.path)
|
||||||
fill_in 'individual_nom', with: 'Nom'
|
fill_in 'individual_nom', with: 'Nom'
|
||||||
fill_in 'individual_prenom', with: 'Prenom'
|
fill_in 'individual_prenom', with: 'Prenom'
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when birthday is asked" do
|
shared_examples 'the user can create a new draft' do
|
||||||
|
it do
|
||||||
|
click_button('Continuer')
|
||||||
|
|
||||||
|
expect(page).to have_current_path(users_dossier_carte_path(procedure.dossiers.last.id))
|
||||||
|
click_button('Etape suivante')
|
||||||
|
|
||||||
|
expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last))
|
||||||
|
|
||||||
|
expect(user.dossiers.first.individual.birthdate).to eq(expected_birthday)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the birthday is asked' do
|
||||||
let(:ask_birthday) { true }
|
let(:ask_birthday) { true }
|
||||||
|
let(:expected_birthday) { Date.new(1987, 10, 14) }
|
||||||
|
|
||||||
scenario "with a proper date input field for birthdate (type='date' supported)" do
|
before do
|
||||||
fill_in 'individual_birthdate', with: '1987-10-14'
|
fill_in 'individual_birthdate', with: birthday_format
|
||||||
click_button('Continuer')
|
|
||||||
|
|
||||||
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id))
|
|
||||||
click_button('Etape suivante')
|
|
||||||
|
|
||||||
expect(page).to have_current_path(brouillon_dossier_path(procedure_for_individual.dossiers.last))
|
|
||||||
|
|
||||||
expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "with a basic text input field for birthdate (type='date' unsupported)" do
|
context 'when the browser supports `type=date` input fields' do
|
||||||
fill_in 'individual_birthdate', with: '14/10/1987'
|
let(:birthday_format) { '1987-10-14' }
|
||||||
click_button('Continuer')
|
it_behaves_like 'the user can create a new draft'
|
||||||
|
end
|
||||||
|
|
||||||
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s))
|
context 'when the browser does not support `type=date` input fields' do
|
||||||
click_button('Etape suivante')
|
let(:birthday_format) { '1987-10-14' }
|
||||||
|
it_behaves_like 'the user can create a new draft'
|
||||||
expect(page).to have_current_path(brouillon_dossier_path(procedure_for_individual.dossiers.last))
|
|
||||||
|
|
||||||
expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when birthday is not asked" do
|
context 'when the birthday is not asked' do
|
||||||
let(:ask_birthday) { false }
|
let(:ask_birthday) { false }
|
||||||
|
let(:expected_birthday) { nil }
|
||||||
scenario "no need for birthday" do
|
it_behaves_like 'the user can create a new draft'
|
||||||
click_button('Continuer')
|
|
||||||
|
|
||||||
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last))
|
|
||||||
click_button('Etape suivante')
|
|
||||||
|
|
||||||
expect(page).to have_current_path(brouillon_dossier_path(procedure_for_individual.dossiers.last))
|
|
||||||
|
|
||||||
expect(user.dossiers.first.individual.birthdate).to eq(nil)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Identification through siret', vcr: { cassette_name: 'api_adresse_search_paris_3' }, js: true do
|
context 'when identifying through SIRET' do
|
||||||
login_as user, scope: :user
|
let(:procedure) { create(:procedure, :published, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) }
|
||||||
visit commencer_path(procedure_path: procedure_with_siret.path)
|
|
||||||
expect(page).to have_current_path(users_dossier_path(procedure_with_siret.dossiers.last.id.to_s))
|
|
||||||
|
|
||||||
|
before do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
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'))
|
.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=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/)
|
||||||
|
@ -74,6 +72,12 @@ feature 'As a User I wanna create a dossier' do
|
||||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/exercices.json'))
|
.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=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
|
||||||
.to_return(status: 404, body: '')
|
.to_return(status: 404, body: '')
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
page.find_by_id('dossier-siret').set siret
|
||||||
click_on 'Valider'
|
click_on 'Valider'
|
||||||
|
@ -81,9 +85,10 @@ feature 'As a User I wanna create a dossier' do
|
||||||
|
|
||||||
expect(page).to have_css('#recap-info-entreprise')
|
expect(page).to have_css('#recap-info-entreprise')
|
||||||
click_on 'Etape suivante'
|
click_on 'Etape suivante'
|
||||||
expect(page).to have_current_path(users_dossier_carte_path(procedure_with_siret.dossiers.last.id.to_s))
|
expect(page).to have_current_path(users_dossier_carte_path(procedure.dossiers.last.id.to_s))
|
||||||
click_on 'Etape suivante'
|
click_on 'Etape suivante'
|
||||||
expect(page).to have_current_path(brouillon_dossier_path(procedure_with_siret.dossiers.last))
|
expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue