2016-12-19 17:15:59 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-02-13 11:57:35 +01:00
|
|
|
feature 'As a User I wanna create a dossier' do
|
2016-12-19 17:15:59 +01:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:siret) { '40307130100044' }
|
|
|
|
let(:siren) { siret[0...9] }
|
|
|
|
|
|
|
|
context 'Right after sign_in I shall see inscription by credentials/siret, I can create a new Dossier' do
|
|
|
|
let(:procedure_with_siret) { create(:procedure, :published, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) }
|
2018-02-06 16:58:04 +01:00
|
|
|
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) }
|
2016-12-19 17:15:59 +01:00
|
|
|
|
2017-03-28 18:06:49 +02:00
|
|
|
context 'Identification for individual' do
|
|
|
|
before do
|
|
|
|
login_as user, scope: :user
|
|
|
|
visit commencer_path(procedure_path: procedure_for_individual.path)
|
2018-02-12 15:55:51 +01:00
|
|
|
fill_in 'individual_nom', with: 'Nom'
|
|
|
|
fill_in 'individual_prenom', with: 'Prenom'
|
2017-03-28 18:06:49 +02:00
|
|
|
end
|
|
|
|
|
2018-02-06 16:58:04 +01:00
|
|
|
context "when birthday is asked" do
|
|
|
|
let(:ask_birthday) { true }
|
|
|
|
|
|
|
|
scenario "with a proper date input field for birthdate (type='date' supported)" do
|
2018-02-12 15:55:51 +01:00
|
|
|
fill_in 'individual_birthdate', with: '1987-10-14'
|
|
|
|
click_button('Continuer')
|
|
|
|
|
|
|
|
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id))
|
|
|
|
click_button('Etape suivante')
|
|
|
|
|
2018-09-06 09:09:23 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(procedure_for_individual.dossiers.last))
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-04-03 16:38:54 +02:00
|
|
|
expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14))
|
2018-02-06 16:58:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario "with a basic text input field for birthdate (type='date' unsupported)" do
|
2018-02-12 15:55:51 +01:00
|
|
|
fill_in 'individual_birthdate', with: '14/10/1987'
|
|
|
|
click_button('Continuer')
|
|
|
|
|
2018-02-06 16:58:04 +01:00
|
|
|
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s))
|
2018-02-12 15:55:51 +01:00
|
|
|
click_button('Etape suivante')
|
|
|
|
|
2018-09-06 09:09:23 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(procedure_for_individual.dossiers.last))
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-04-03 16:38:54 +02:00
|
|
|
expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14))
|
2018-02-06 16:58:04 +01:00
|
|
|
end
|
2017-03-28 18:06:49 +02:00
|
|
|
end
|
|
|
|
|
2018-02-06 16:58:04 +01:00
|
|
|
context "when birthday is not asked" do
|
|
|
|
let(:ask_birthday) { false }
|
|
|
|
|
|
|
|
scenario "no need for birthday" do
|
2018-02-12 15:55:51 +01:00
|
|
|
click_button('Continuer')
|
|
|
|
|
2018-02-21 18:36:06 +01:00
|
|
|
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last))
|
2018-02-12 15:55:51 +01:00
|
|
|
click_button('Etape suivante')
|
|
|
|
|
2018-09-06 09:09:23 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(procedure_for_individual.dossiers.last))
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-02-06 16:58:04 +01:00
|
|
|
expect(user.dossiers.first.individual.birthdate).to eq(nil)
|
|
|
|
end
|
2017-03-28 18:06:49 +02:00
|
|
|
end
|
2016-12-19 17:15:59 +01:00
|
|
|
end
|
|
|
|
|
2018-10-15 16:33:42 +02:00
|
|
|
scenario 'Identification through siret', vcr: { cassette_name: 'api_adresse_search_paris_3' }, js: true do
|
2016-12-19 17:15:59 +01:00
|
|
|
login_as user, scope: :user
|
|
|
|
visit commencer_path(procedure_path: procedure_with_siret.path)
|
2018-01-23 17:14:13 +01:00
|
|
|
expect(page).to have_current_path(users_dossier_path(procedure_with_siret.dossiers.last.id.to_s))
|
2018-08-01 11:00:54 +02:00
|
|
|
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
2018-10-15 17:04:51 +02:00
|
|
|
.to_return(status: 200, body: File.read('spec/support/files/api_entreprise/etablissements.json'))
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/)
|
2018-10-15 17:04:51 +02:00
|
|
|
.to_return(status: 200, body: File.read('spec/support/files/api_entreprise/entreprises.json'))
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/#{siret}?.*token=/)
|
2018-10-15 17:04:51 +02:00
|
|
|
.to_return(status: 200, body: File.read('spec/support/files/api_entreprise/exercices.json'))
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(status: 404, body: '')
|
2018-08-01 11:00:54 +02:00
|
|
|
|
2017-04-12 11:12:05 +02:00
|
|
|
page.find_by_id('dossier-siret').set siret
|
2018-10-02 13:51:56 +02:00
|
|
|
click_on 'Valider'
|
2018-08-01 11:01:46 +02:00
|
|
|
wait_for_ajax
|
|
|
|
|
2017-04-12 11:12:05 +02:00
|
|
|
expect(page).to have_css('#recap-info-entreprise')
|
2018-10-02 13:51:56 +02:00
|
|
|
click_on 'Etape suivante'
|
2018-01-23 17:14:13 +01:00
|
|
|
expect(page).to have_current_path(users_dossier_carte_path(procedure_with_siret.dossiers.last.id.to_s))
|
2018-10-02 13:51:56 +02:00
|
|
|
click_on 'Etape suivante'
|
2018-09-06 09:09:23 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(procedure_with_siret.dossiers.last))
|
2016-12-19 17:15:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|