Merge pull request #2760 from betagouv/migrate-siret

Migre la page SIRET vers le nouveau design
This commit is contained in:
gregoirenovel 2018-10-17 10:42:35 +02:00 committed by GitHub
commit dcb9a75fae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 592 additions and 243 deletions

View file

@ -0,0 +1,54 @@
@import "constants";
@import "colors";
.etablissement {
margin-top: $default-padding * 2;
margin-bottom: $default-padding * 2;
h1 {
margin-bottom: $default-padding * 2;
}
p {
margin-bottom: $default-padding;
}
.etablissement-infos {
margin-top: $default-padding * 2;
margin-bottom: $default-padding * 2;
> * {
margin-bottom: $default-padding;
&:last-child {
margin-bottom: 0;
}
}
ul {
line-height: 28px;
list-style-type: disc;
list-style-position: inside;
// Inner lists
ul {
margin-left: $default-padding;
list-style-type: circle;
}
}
.etablissement-exercices {
font-style: italic;
}
}
.actions {
display: flex;
flex-wrap: wrap-reverse;
justify-content: space-between;
.button {
margin-bottom: $default-padding;
}
}
}

View file

@ -69,6 +69,50 @@ module NewUser
end
end
def siret
@dossier = dossier
end
def update_siret
@dossier = dossier
# We use the user as the holder model object for the siret value
# (so that we can restore it on the form in case of error).
#
# This is the only remaining use of User#siret: it could be refactored away.
# However some existing users have a siret but no associated etablissement,
# so we would need to analyze the legacy data and decide what to do with it.
current_user.siret = siret_params[:siret]
siret_model = Siret.new(siret: siret_params[:siret])
if !siret_model.valid?
return render_siret_error(siret_model.errors.full_messages)
end
sanitized_siret = siret_model.siret
etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(sanitized_siret, @dossier.procedure.id)
if etablissement_attributes.blank?
return render_siret_error(t('errors.messages.siret_unknown'))
end
etablissement = @dossier.build_etablissement(etablissement_attributes)
etablissement.save!
current_user.update!(siret: sanitized_siret)
@dossier.update!(autorisation_donnees: true)
redirect_to etablissement_dossier_path
end
def etablissement
@dossier = dossier
# Redirect if the user attempts to access the page URL directly
if !@dossier.etablissement
flash.alert = 'Aucun établissement nest associé à ce dossier'
return redirect_to siret_dossier_path(@dossier)
end
end
def brouillon
@dossier = dossier_with_champs
@ -77,7 +121,7 @@ module NewUser
if dossier.procedure.for_individual
redirect_to identite_dossier_path(@dossier)
else
redirect_to users_dossier_path(@dossier)
redirect_to siret_dossier_path(@dossier)
end
end
end
@ -251,10 +295,19 @@ module NewUser
redirect_to root_path
end
def render_siret_error(error_message)
flash.alert = error_message
render :siret
end
def individual_params
params.require(:individual).permit(:gender, :nom, :prenom, :birthdate)
end
def siret_params
params.require(:user).permit(:siret)
end
def commentaire_params
params.require(:commentaire).permit(:body, :file)
end

View file

@ -61,7 +61,7 @@ class Users::DossiersController < UsersController
if dossier.procedure.for_individual
redirect_to identite_dossier_path(dossier)
else
redirect_to users_dossier_path(id: dossier.id)
redirect_to siret_dossier_path(id: dossier.id)
end
rescue ActiveRecord::RecordNotFound
error_procedure

View file

@ -0,0 +1,9 @@
.procedure-logos
= image_tag procedure.decorate.logo_img
- if procedure.euro_flag
= image_tag "flag_of_europe.svg"
%h2.procedure-title
= procedure.libelle
.procedure-description
= h string_to_html(procedure.description)

View file

@ -0,0 +1,35 @@
- content_for(:title, "Informations sur létablissement")
- content_for :footer do
= render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier }
.etablissement
.container
%h1 Informations sur létablissement
%p
Nous avons récupéré auprès de lINSEE et dInfogreffe les informations suivantes concernant votre établissement.
%p
Ces informations seront jointes à votre dossier.
.etablissement-infos.card.featured
- etablissement = @dossier.etablissement
%h2.card-title= raison_sociale_or_name(etablissement)
= render partial: 'new_user/dossiers/etablissement/infos_entreprise', locals: { etablissement: etablissement }
- if etablissement.association?
= render partial: 'new_user/dossiers/etablissement/infos_association', locals: { etablissement: etablissement }
.actions
= link_to 'Utiliser un autre numéro SIRET', siret_dossier_path(@dossier), class: 'button'
- if @dossier.procedure.use_api_carto
/ Until the old layout is gone, we need to disable turbolinks
/ to avoid the map loading twice (once for the turbolinks preview,
/ once when turbolinks notices the layout are differents and reloads
/ the page.)
= link_to 'Continuer avec ces informations', users_dossier_carte_path(@dossier), class: 'button primary', data: { turbolinks: false }
- else
= link_to 'Continuer avec ces informations', brouillon_dossier_path(@dossier), class: 'button primary'

View file

@ -0,0 +1,24 @@
%ul.etablissement-infos-association
%li
Numéro denregistrement au Registre National des Associations :
= etablissement.association_rna
%li
Titre :
= etablissement.association_titre
%li
Objet :
= etablissement.association_objet
%li
Date de création :
= etablissement.association_date_creation&.strftime('%d/%m/%Y')
%li
Date de déclaration :
= etablissement.association_date_declaration&.strftime('%d/%m/%Y')
%li
Date de publication :
= etablissement.association_date_publication&.strftime('%d/%m/%Y')

View file

@ -0,0 +1,49 @@
%ul.etablissement-infos-entreprise
%li
Siret :
= etablissement.siret
- if etablissement.siret != etablissement.entreprise.siret_siege_social
%li
SIRET siègle social :
= etablissement.entreprise.siret_siege_social
%li
Forme juridique :
= etablissement.entreprise.forme_juridique
%li
Libellé NAF :
= etablissement.libelle_naf
%li
Code NAF :
= etablissement.naf
%li
Date de création :
= etablissement.entreprise.date_creation&.strftime('%d/%m/%Y')
%li
Effectif organisation :
= effectif(etablissement)
%li
Code effectif :
= etablissement.entreprise.code_effectif_entreprise
%li
Numéro TVA intracommunautaire :
= etablissement.entreprise.numero_tva_intracommunautaire
%li
Adresse :
- etablissement.adresse.split("\n").each do |line|
= line
%li
Capital social :
= pretty_currency(etablissement.entreprise.capital_social)
- if etablissement.exercices.present?
%p.etablissement-exercices Les exercices comptables des trois dernières années seront joints à votre dossier.

View file

@ -6,15 +6,7 @@
.two-columns
.columns-container
.column.preview
.procedure-logos
= image_tag @dossier.procedure.decorate.logo_img
- if @dossier.procedure.euro_flag
= image_tag "flag_of_europe.svg"
%h2.procedure-title
= @dossier.procedure.libelle
.procedure-description
= h string_to_html(@dossier.procedure.description)
= render partial: "new_user/dossiers/demarche_overview", locals: { procedure: @dossier.procedure }
.column.identity-form
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: @dossier }

View file

@ -0,0 +1,25 @@
- content_for(:title, "Nouveau dossier (#{@dossier.procedure.libelle})")
- content_for :footer do
= render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier }
.two-columns
.columns-container
.column.preview
= render partial: "new_user/dossiers/demarche_overview", locals: { procedure: @dossier.procedure }
.column.identity-form
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: @dossier }
- if !dossier_submission_is_closed?(@dossier)
= form_for current_user, url: siret_dossier_path(@dossier), html: { class: 'form', method: 'post' } do |f|
%h1 Identifier votre établissement
%p.mb-1 Merci de remplir le numéro de SIRET de votre entreprise, administration ou association pour commencer la démarche.
= f.label :siret, style: "display: none"
= f.text_field :siret, placeholder: "Numéro SIRET à 14 chiffres", required: true
= f.hidden_field :dossier_id, value: @dossier.id
= f.submit "Valider", class: "button large primary expand", data: { disable_with: "Récupération des informations…" }

View file

@ -113,6 +113,7 @@ fr:
activerecord:
attributes:
user:
siret: 'Numéro SIRET'
password: 'Le mot de passe'
gestionnaire:
password: 'Le mot de passe'
@ -170,6 +171,8 @@ fr:
dossier_map_not_activated: "Le dossier n'a pas accès à la cartographie."
invalid_siret: "Le siret est incorrect"
procedure_not_found: "La démarche n'existe pas"
siret_unknown: 'Désolé, nous navons pas trouvé détablissement enregistré correspondant à ce numéro SIRET'
etablissement_fail: 'Désolé, nous navons pas réussi à enregistrer létablissement correspondant à ce numéro SIRET'
france_connect:
connexion: "Erreur lors de la connexion à France Connect."
extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide."

View file

@ -0,0 +1,12 @@
fr:
activemodel:
models:
siret: 'SIRET'
errors:
models:
siret:
attributes:
siret:
format: 'Le numéro SIRET doit comporter 14 chiffres'
checksum: 'Le numéro SIRET comporte une erreur, vérifiez les chiffres composant le numéro'
invalid: 'Le numéro SIRET ne correspond pas à un établissement existant'

View file

@ -278,6 +278,9 @@ Rails.application.routes.draw do
member do
get 'identite'
patch 'update_identite'
get 'siret'
post 'siret', to: 'dossiers#update_siret'
get 'etablissement'
get 'brouillon'
patch 'brouillon', to: 'dossiers#update_brouillon'
get 'modifier', to: 'dossiers#modifier'

View file

@ -205,6 +205,151 @@ describe NewUser::DossiersController, type: :controller do
end
end
describe '#siret' do
before { sign_in(user) }
let!(:dossier) { create(:dossier, user: user) }
subject { get :siret, params: { id: dossier.id } }
it { is_expected.to render_template(:siret) }
end
describe '#update_siret' do
let(:dossier) { create(:dossier, user: user) }
let(:siret) { params_siret.delete(' ') }
let(:siren) { siret[0..8] }
let(:api_etablissement_status) { 200 }
let(:api_etablissement_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
let(:api_entreprise_status) { 200 }
let(:api_entreprise_body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') }
let(:api_exercices_status) { 200 }
let(:api_exercices_body) { File.read('spec/fixtures/files/api_entreprise/exercices.json') }
let(:api_association_status) { 200 }
let(:api_association_body) { File.read('spec/fixtures/files/api_entreprise/associations.json') }
def stub_api_entreprise_requests
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
.to_return(status: api_etablissement_status, body: api_etablissement_body)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/)
.to_return(status: api_entreprise_status, body: api_entreprise_body)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/#{siret}?.*token=/)
.to_return(status: api_exercices_status, body: api_exercices_body)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
.to_return(status: api_association_status, body: api_association_body)
end
before do
sign_in(user)
stub_api_entreprise_requests
end
subject! { post :update_siret, params: { id: dossier.id, user: { siret: params_siret } } }
shared_examples 'SIRET informations are successfully saved' do
it do
dossier.reload
user.reload
expect(dossier.etablissement).to be_present
expect(dossier.autorisation_donnees).to be(true)
expect(user.siret).to eq(siret)
expect(response).to redirect_to(etablissement_dossier_path)
end
end
shared_examples 'the request fails with an error' do |error|
it 'doesnt save an etablissement' do
expect(dossier.reload.etablissement).to be_nil
end
it 'displays the SIRET that was sent by the user in the form' do
expect(controller.current_user.siret).to eq(siret)
end
it 'renders an error' do
expect(flash.alert).to eq(error)
expect(response).to render_template(:siret)
end
end
context 'with an invalid SIRET' do
let(:params_siret) { '000 000' }
it_behaves_like 'the request fails with an error', ['Siret Le numéro SIRET doit comporter 14 chiffres']
end
context 'with a valid SIRET' do
let(:params_siret) { '440 117 620 01530' }
context 'when API-Entreprise doesnt know this SIRET' do
let(:api_etablissement_status) { 404 }
let(:api_body_status) { '' }
it_behaves_like 'the request fails with an error', I18n.t('errors.messages.siret_unknown')
end
context 'when the API returns no Entreprise' do
let(:api_entreprise_status) { 404 }
let(:api_entreprise_body) { '' }
it_behaves_like 'the request fails with an error', I18n.t('errors.messages.siret_unknown')
end
context 'when the API returns no Exercices' do
let(:api_exercices_status) { 404 }
let(:api_exercices_body) { '' }
it_behaves_like 'SIRET informations are successfully saved'
it 'doesnt save the etablissement exercices' do
expect(dossier.reload.etablissement.exercices).to be_empty
end
end
context 'when the RNA doesnt have informations on the SIRET' do
let(:api_association_status) { 404 }
let(:api_association_body) { '' }
it_behaves_like 'SIRET informations are successfully saved'
it 'doesnt save the RNA informations' do
expect(dossier.reload.etablissement.association?).to be(false)
end
end
context 'when all API informations available' do
it_behaves_like 'SIRET informations are successfully saved'
it 'saves the associated informations on the etablissement' do
dossier.reload
expect(dossier.etablissement.entreprise).to be_present
expect(dossier.etablissement.exercices).to be_present
expect(dossier.etablissement.association?).to be(true)
end
end
end
end
describe '#etablissement' do
let(:dossier) { create(:dossier, :with_entreprise, user: user) }
before { sign_in(user) }
subject { get :etablissement, params: { id: dossier.id } }
it { is_expected.to render_template(:etablissement) }
context 'when the dossier has no etablissement yet' do
let(:dossier) { create(:dossier, user: user) }
it { is_expected.to redirect_to siret_dossier_path(dossier) }
end
end
describe '#brouillon' do
before { sign_in(user) }
let!(:dossier) { create(:dossier, user: user, autorisation_donnees: true) }
@ -219,7 +364,7 @@ describe NewUser::DossiersController, type: :controller do
before { dossier.update_columns(autorisation_donnees: false) }
context 'when the dossier is for personne morale' do
it { is_expected.to redirect_to(users_dossier_path(dossier)) }
it { is_expected.to redirect_to(siret_dossier_path(dossier)) }
end
context 'when the dossier is for an personne physique' do

View file

@ -61,7 +61,7 @@ describe Users::DossiersController, type: :controller do
end
it { is_expected.to have_http_status(302) }
it { is_expected.to redirect_to users_dossier_path(id: Dossier.last) }
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
it { expect { subject }.to change(Dossier, :count).by 1 }
@ -152,7 +152,7 @@ describe Users::DossiersController, type: :controller do
subject { get :new, params: { procedure_id: procedure_id, brouillon: true } }
it { is_expected.to have_http_status(302) }
it { is_expected.to redirect_to users_dossier_path(id: Dossier.last) }
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
end
end
end

View file

@ -23,6 +23,12 @@ FactoryBot.define do
entreprise_siret_siege_social { '44011762001530' }
entreprise_code_effectif_entreprise { '51' }
entreprise_date_creation { "1990-04-24" }
trait :with_exercices do
after(:create) do |etablissement, _evaluator|
create(:exercice, etablissement: etablissement)
end
end
end
trait :is_association do

View file

@ -0,0 +1,108 @@
require 'spec_helper'
feature 'Creating a new dossier:' do
let(:user) { create(:user) }
let(:siret) { '40307130100044' }
let(:siren) { siret[0...9] }
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
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_prenom', with: 'Prenom'
end
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(:expected_birthday) { Date.new(1987, 10, 14) }
before do
fill_in 'individual_birthdate', with: birthday_format
end
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
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'
end
end
context 'when the birthday is not asked' do
let(:ask_birthday) { false }
let(:expected_birthday) { nil }
it_behaves_like 'the user can create a new draft'
end
end
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=/)
.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
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)
expect(page).to have_current_path(siret_dossier_path(dossier))
fill_in 'Numéro SIRET', with: siret
click_on 'Valider'
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
end

View file

@ -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

View file

@ -1,89 +0,0 @@
require 'spec_helper'
feature 'As a User I wanna create a dossier' do
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) }
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
login_as user, scope: :user
visit commencer_path(procedure_path: procedure_for_individual.path)
fill_in 'individual_nom', with: 'Nom'
fill_in 'individual_prenom', with: 'Prenom'
end
context "when birthday is asked" do
let(:ask_birthday) { true }
scenario "with a proper date input field for birthdate (type='date' supported)" do
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')
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
scenario "with a basic text input field for birthdate (type='date' unsupported)" do
fill_in 'individual_birthdate', with: '14/10/1987'
click_button('Continuer')
expect(page).to have_current_path(users_dossier_carte_path(procedure_for_individual.dossiers.last.id.to_s))
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
context "when birthday is not asked" do
let(:ask_birthday) { false }
scenario "no need for birthday" do
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
scenario 'Identification through siret', vcr: { cassette_name: 'api_adresse_search_paris_3' }, js: true do
login_as user, scope: :user
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))
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
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_with_siret.dossiers.last.id.to_s))
click_on 'Etape suivante'
expect(page).to have_current_path(brouillon_dossier_path(procedure_with_siret.dossiers.last))
end
end
end

View file

@ -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

View file

@ -0,0 +1,35 @@
require 'spec_helper'
describe 'new_user/dossiers/etablissement.html.haml', type: :view do
let(:etablissement) { create(:etablissement, :with_exercices) }
let(:dossier) { create(:dossier, etablissement: etablissement) }
let(:footer) { view.content_for(:footer) }
before do
sign_in dossier.user
assign(:dossier, dossier)
end
subject! { render }
it 'affiche les informations de létablissement' do
expect(rendered).to have_text(etablissement.entreprise_raison_sociale)
expect(rendered).to have_text(etablissement.siret)
end
it 'naffiche pas publiquement les derniers exercices comptables' do
expect(rendered).not_to have_text(number_to_currency(etablissement.exercices.first.ca))
end
context 'quand létablissement est une association' do
let(:etablissement) { create(:etablissement, :is_association) }
it 'affiche les informations de lassociation' do
expect(rendered).to have_text(etablissement.association_titre)
end
end
it 'prépare le footer' do
expect(footer).to have_selector('footer')
end
end

View file

@ -0,0 +1,25 @@
require 'spec_helper'
describe 'new_user/dossiers/siret.html.haml', type: :view do
let(:dossier) { create(:dossier) }
let(:footer) { view.content_for(:footer) }
before do
sign_in dossier.user
assign(:dossier, dossier)
end
subject! { render }
it 'affiche les informations de la démarche' do
expect(rendered).to have_text(dossier.procedure.libelle)
end
it 'affiche le formulaire de SIRET' do
expect(rendered).to have_field('Numéro SIRET')
end
it 'prépare le footer' do
expect(footer).to have_selector('footer')
end
end