2016-12-19 17:15:59 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
feature 'Creating a new dossier:' do
|
2016-12-19 17:15:59 +01:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:siret) { '40307130100044' }
|
|
|
|
let(:siren) { siret[0...9] }
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
context 'when the user is already signed in' do
|
|
|
|
before do
|
|
|
|
login_as user, scope: :user
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the procedure has identification by individual' do
|
2019-01-07 12:17:11 +01:00
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, :with_type_de_champ, :with_two_type_de_piece_justificative, ask_birthday: ask_birthday) }
|
2018-10-15 15:46:23 +02:00
|
|
|
let(:ask_birthday) { false }
|
|
|
|
let(:expected_birthday) { nil }
|
2016-12-19 17:15:59 +01:00
|
|
|
|
2017-03-28 18:06:49 +02:00
|
|
|
before do
|
2018-10-30 12:00:58 +01:00
|
|
|
visit commencer_path(path: procedure.path)
|
2019-01-07 12:17:11 +01:00
|
|
|
|
|
|
|
expect(page).to have_content(procedure.libelle)
|
|
|
|
expect(page).to have_content(procedure.description)
|
|
|
|
expect(page).to have_content(procedure.service.email)
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
fill_in 'individual_nom', with: 'Nom'
|
|
|
|
fill_in 'individual_prenom', with: 'Prenom'
|
2017-03-28 18:06:49 +02:00
|
|
|
end
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
shared_examples 'the user can create a new draft' do
|
|
|
|
it do
|
2018-02-12 15:55:51 +01:00
|
|
|
click_button('Continuer')
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last))
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
expect(user.dossiers.first.individual.birthdate).to eq(expected_birthday)
|
2018-02-06 16:58:04 +01:00
|
|
|
end
|
2018-10-15 15:46:23 +02:00
|
|
|
end
|
2018-02-06 16:58:04 +01:00
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
context 'when the birthday is asked' do
|
|
|
|
let(:ask_birthday) { true }
|
|
|
|
let(:expected_birthday) { Date.new(1987, 10, 14) }
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
before do
|
|
|
|
fill_in 'individual_birthdate', with: birthday_format
|
|
|
|
end
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
context 'when the browser supports `type=date` input fields' do
|
|
|
|
let(:birthday_format) { '1987-10-14' }
|
|
|
|
it_behaves_like 'the user can create a new draft'
|
|
|
|
end
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
context 'when the browser does not support `type=date` input fields' do
|
|
|
|
let(:birthday_format) { '1987-10-14' }
|
|
|
|
it_behaves_like 'the user can create a new draft'
|
2018-02-06 16:58:04 +01:00
|
|
|
end
|
2017-03-28 18:06:49 +02:00
|
|
|
end
|
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
context 'when the birthday is not asked' do
|
2018-02-06 16:58:04 +01:00
|
|
|
let(:ask_birthday) { false }
|
2018-10-15 15:46:23 +02:00
|
|
|
let(:expected_birthday) { nil }
|
|
|
|
it_behaves_like 'the user can create a new draft'
|
|
|
|
end
|
|
|
|
end
|
2018-02-06 16:58:04 +01:00
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
context 'when identifying through SIRET' do
|
2019-01-07 12:17:11 +01:00
|
|
|
let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ, :with_two_type_de_piece_justificative) }
|
2018-10-16 17:52:34 +02:00
|
|
|
let(:dossier) { procedure.dossiers.last }
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
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: '')
|
|
|
|
end
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
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
|
2018-10-30 12:00:58 +01:00
|
|
|
visit commencer_path(path: procedure.path)
|
2019-01-07 12:17:11 +01:00
|
|
|
|
2018-10-15 15:46:23 +02:00
|
|
|
expect(page).to have_current_path(siret_dossier_path(dossier))
|
2019-01-07 12:17:11 +01:00
|
|
|
expect(page).to have_content(procedure.libelle)
|
|
|
|
expect(page).to have_content(procedure.description)
|
|
|
|
expect(page).to have_content(procedure.service.email)
|
2018-02-12 15:55:51 +01:00
|
|
|
|
2018-10-16 17:52:34 +02:00
|
|
|
fill_in 'Numéro SIRET', with: siret
|
2018-10-15 15:46:23 +02:00
|
|
|
click_on 'Valider'
|
2016-12-19 17:15:59 +01:00
|
|
|
|
2018-10-16 17:52:34 +02:00
|
|
|
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(brouillon_dossier_path(dossier))
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'the user is notified when its SIRET is invalid' do
|
2018-10-30 12:00:58 +01:00
|
|
|
visit commencer_path(path: procedure.path)
|
2018-10-16 17:52:34 +02:00
|
|
|
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')
|
2018-10-15 15:46:23 +02:00
|
|
|
end
|
2016-12-19 17:15:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|