New UI and UX for the dossier initialization
This commit is contained in:
parent
5c2902bda5
commit
cc8d2ef4ee
26 changed files with 451 additions and 156 deletions
34
app/assets/javascripts/dossiers.js
Normal file
34
app/assets/javascripts/dossiers.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
$(document).on('page:load', the_terms);
|
||||
$(document).ready(the_terms);
|
||||
|
||||
function the_terms() {
|
||||
var the_terms = $("#dossier_autorisation_donnees");
|
||||
|
||||
if(the_terms.size() == 0)
|
||||
return;
|
||||
|
||||
check_value (the_terms);
|
||||
|
||||
the_terms.click(function () {
|
||||
check_value (the_terms);
|
||||
});
|
||||
|
||||
function check_value (the_terms){
|
||||
if (the_terms.is(":checked")) {
|
||||
$("#etape_suivante").removeAttr("disabled");
|
||||
} else {
|
||||
$("#etape_suivante").attr("disabled", "disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function error_form_siret(invalid_siret){
|
||||
$("input[type='submit']").removeClass('btn-success').addClass('btn-danger').val('Erreur SIRET');
|
||||
$("#dossier_siret").addClass('input-error').val(invalid_siret).on('input', reset_form_siret);
|
||||
|
||||
}
|
||||
|
||||
function reset_form_siret(){
|
||||
$("input[type='submit']").removeClass('btn-danger').addClass('btn-success').val('Valider');
|
||||
$("#dossier_siret").removeClass('input-error');
|
||||
}
|
|
@ -186,7 +186,8 @@ div.pagination {
|
|||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.alert.alert-success.move_up {
|
||||
.alert.alert-success.move_up,
|
||||
.alert.alert-danger.siret{
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
left: 0;
|
||||
|
|
29
app/assets/stylesheets/etapes.scss
Normal file
29
app/assets/stylesheets/etapes.scss
Normal file
|
@ -0,0 +1,29 @@
|
|||
.etapes_menu{
|
||||
h3 {
|
||||
margin-left: 3%;
|
||||
}
|
||||
padding-right: 0 !important;
|
||||
}
|
||||
|
||||
.etapes_informations {
|
||||
padding-left: 0 !important;
|
||||
}
|
||||
|
||||
.etape{
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.etape_2{
|
||||
.etapes_menu{
|
||||
#dossier_siret{
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
button{
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
.etapes_informations{
|
||||
padding-top: 15px;
|
||||
}
|
||||
}
|
|
@ -6,13 +6,6 @@
|
|||
display: none;
|
||||
}
|
||||
|
||||
#dossier_siret {
|
||||
margin-bottom: 10px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
#titre_procedure {
|
||||
margin-top: 3%;
|
||||
margin-bottom: 2%;
|
||||
|
|
|
@ -3,7 +3,7 @@ class Users::DossiersController < UsersController
|
|||
helper SmartListing::Helper
|
||||
|
||||
before_action :authenticate_user!
|
||||
before_action :check_siret, only: :create
|
||||
before_action :check_siret, only: :siret_informations
|
||||
|
||||
before_action only: [:show] do
|
||||
authorized_routes? self.class
|
||||
|
@ -25,50 +25,53 @@ class Users::DossiersController < UsersController
|
|||
def new
|
||||
procedure = Procedure.where(archived: false, published: true).find(params[:procedure_id])
|
||||
|
||||
@dossier = Dossier.new(procedure: procedure)
|
||||
@siret = params[:siret] || current_user.siret
|
||||
dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft')
|
||||
siret = params[:siret] || current_user.siret
|
||||
|
||||
update_current_user_siret! siret unless siret.nil?
|
||||
|
||||
redirect_to users_dossier_path(id: dossier.id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
error_procedure
|
||||
end
|
||||
|
||||
def show
|
||||
@facade = DossierFacades.new params[:id], current_user.email
|
||||
@facade = facade
|
||||
@siret = current_user.siret unless current_user.siret.nil?
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash.alert = t('errors.messages.dossier_not_found')
|
||||
redirect_to url_for users_dossiers_path
|
||||
end
|
||||
|
||||
def create
|
||||
entreprise_adapter = SIADE::EntrepriseAdapter.new(siren)
|
||||
def siret_informations
|
||||
@facade = facade params[:dossier_id]
|
||||
|
||||
dossier = Dossier.create(user: current_user,
|
||||
state: 'draft',
|
||||
procedure_id: create_params[:procedure_id],
|
||||
mandataire_social: mandataire_social?(entreprise_adapter.mandataires_sociaux))
|
||||
update_current_user_siret! siret
|
||||
|
||||
entreprise = dossier.create_entreprise(entreprise_adapter.to_params)
|
||||
DossierService.new(@facade.dossier, siret, current_user.france_connect_information).dossier_informations!
|
||||
|
||||
entreprise.create_rna_information(SIADE::RNAAdapter.new(siret).to_params)
|
||||
|
||||
etablissement = dossier.create_etablissement(SIADE::EtablissementAdapter.new(siret).to_params
|
||||
.merge({entreprise_id: entreprise.id}))
|
||||
|
||||
etablissement.exercices.create(SIADE::ExercicesAdapter.new(siret).to_params)
|
||||
|
||||
redirect_to url_for(controller: :dossiers, action: :show, id: dossier.id)
|
||||
@facade = facade params[:dossier_id]
|
||||
render '/dossiers/new_siret', formats: 'js'
|
||||
|
||||
rescue RestClient::ResourceNotFound
|
||||
errors_valid_siret
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash.alert = t('errors.messages.dossier_not_found')
|
||||
redirect_to url_for(controller: :siret)
|
||||
redirect_to url_for users_dossiers_path
|
||||
end
|
||||
|
||||
def change_siret
|
||||
Dossier.find(params[:dossier_id]).reset!
|
||||
|
||||
@facade = facade params[:dossier_id]
|
||||
|
||||
render '/dossiers/new_siret', formats: :js
|
||||
end
|
||||
|
||||
def update
|
||||
@facade = DossierFacades.new params[:id], current_user.email
|
||||
@facade = facade params[:dossier][:id]
|
||||
|
||||
if checked_autorisation_donnees?
|
||||
@facade.dossier.update_attributes(update_params)
|
||||
|
@ -79,8 +82,8 @@ class Users::DossiersController < UsersController
|
|||
redirect_to url_for(controller: :description, action: :show, dossier_id: @facade.dossier.id)
|
||||
end
|
||||
else
|
||||
flash.now.alert = 'Les conditions sont obligatoires.'
|
||||
render 'show'
|
||||
flash.alert = 'Les conditions sont obligatoires.'
|
||||
redirect_to users_dossier_path(id: @facade.dossier.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -132,7 +135,9 @@ class Users::DossiersController < UsersController
|
|||
|
||||
def errors_valid_siret
|
||||
flash.alert = t('errors.messages.invalid_siret')
|
||||
redirect_to url_for new_users_dossiers_path(procedure_id: create_params[:procedure_id])
|
||||
@facade = facade params[:dossier_id]
|
||||
|
||||
render '/dossiers/new_siret', formats: :js, locals: {invalid_siret: siret}
|
||||
end
|
||||
|
||||
def update_params
|
||||
|
@ -147,28 +152,21 @@ class Users::DossiersController < UsersController
|
|||
create_params[:siret]
|
||||
end
|
||||
|
||||
def siren
|
||||
siret[0..8]
|
||||
end
|
||||
|
||||
def create_params
|
||||
params.require(:dossier).permit(:siret, :procedure_id)
|
||||
params.require(:dossier).permit(:siret)
|
||||
end
|
||||
|
||||
def error_procedure
|
||||
flash.alert = t('errors.messages.procedure_not_found')
|
||||
|
||||
redirect_to url_for users_dossiers_path
|
||||
end
|
||||
|
||||
def mandataire_social? mandataires_list
|
||||
unless current_user.france_connect_information.nil?
|
||||
mandataires_list.each do |mandataire|
|
||||
return true if mandataire[:nom].upcase == current_user.family_name.upcase &&
|
||||
mandataire[:prenom].upcase == current_user.given_name.upcase &&
|
||||
mandataire[:date_naissance_timestamp] == current_user.birthdate.to_time.to_i
|
||||
end
|
||||
end
|
||||
def update_current_user_siret! siret
|
||||
current_user.update_attributes(siret: siret)
|
||||
end
|
||||
|
||||
false
|
||||
def facade id = params[:id]
|
||||
DossierFacades.new id, current_user.email
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ class DossierFacades
|
|||
end
|
||||
|
||||
def entreprise
|
||||
@dossier.entreprise.decorate
|
||||
@dossier.entreprise.decorate unless @dossier.entreprise.nil?
|
||||
end
|
||||
|
||||
def etablissement
|
||||
|
|
|
@ -193,4 +193,10 @@ class Dossier < ActiveRecord::Base
|
|||
entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map {|k, v| ["entreprise.#{k}", v] }.to_h
|
||||
dossier_attr.merge(etablissement_attr).merge(entreprise_attr)
|
||||
end
|
||||
|
||||
def reset!
|
||||
entreprise.destroy unless entreprise.nil?
|
||||
|
||||
update_attributes(autorisation_donnees: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Entreprise < ActiveRecord::Base
|
||||
belongs_to :dossier
|
||||
has_one :etablissement
|
||||
has_one :rna_information
|
||||
has_one :etablissement, dependent: :destroy
|
||||
has_one :rna_information, dependent: :destroy
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ class Etablissement < ActiveRecord::Base
|
|||
belongs_to :dossier
|
||||
belongs_to :entreprise
|
||||
|
||||
has_many :exercices
|
||||
has_many :exercices, dependent: :destroy
|
||||
|
||||
def geo_adresse
|
||||
[numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ')
|
||||
|
|
68
app/services/dossier_service.rb
Normal file
68
app/services/dossier_service.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
class DossierService
|
||||
|
||||
def initialize dossier, siret, france_connect_information
|
||||
@dossier = dossier
|
||||
@siret = siret
|
||||
@france_connect_information = france_connect_information
|
||||
end
|
||||
|
||||
def dossier_informations!
|
||||
entreprise_thread = Thread.new {
|
||||
@entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret)
|
||||
|
||||
@dossier.create_entreprise(@entreprise_adapter.to_params)
|
||||
}
|
||||
|
||||
etablissement_thread = Thread.new {
|
||||
@etablissement_adapter = SIADE::EtablissementAdapter.new(@siret)
|
||||
|
||||
@dossier.create_etablissement(@etablissement_adapter.to_params)
|
||||
}
|
||||
|
||||
rna_thread = Thread.new {
|
||||
@rna_adapter = SIADE::RNAAdapter.new(@siret)
|
||||
|
||||
sleep(0.1) while entreprise_thread.alive?
|
||||
|
||||
@dossier.entreprise.create_rna_information(@rna_adapter.to_params)
|
||||
}
|
||||
|
||||
exercices_thread = Thread.new {
|
||||
@exercices_adapter = SIADE::ExercicesAdapter.new(@siret)
|
||||
|
||||
sleep(0.1) while etablissement_thread.alive?
|
||||
|
||||
@dossier.etablissement.exercices.create(@exercices_adapter.to_params)
|
||||
}
|
||||
|
||||
sleep(0.1) while entreprise_thread.alive? ||
|
||||
etablissement_thread.alive? ||
|
||||
rna_thread.alive? ||
|
||||
exercices_thread.alive?
|
||||
|
||||
@dossier.update_attributes(mandataire_social: mandataire_social?(@entreprise_adapter.mandataires_sociaux))
|
||||
@dossier.etablissement.update_attributes(entreprise: @dossier.entreprise)
|
||||
|
||||
@dossier
|
||||
end
|
||||
|
||||
|
||||
def self.siren siret
|
||||
siret[0..8]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mandataire_social? mandataires_list
|
||||
unless @france_connect_information.nil?
|
||||
|
||||
mandataires_list.each do |mandataire|
|
||||
return true if mandataire[:nom].upcase == @france_connect_information.family_name.upcase &&
|
||||
mandataire[:prenom].upcase == @france_connect_information.given_name.upcase &&
|
||||
mandataire[:date_naissance_timestamp] == @france_connect_information.birthdate.to_time.to_i
|
||||
end
|
||||
end
|
||||
|
||||
false
|
||||
end
|
||||
end
|
|
@ -1,13 +1,21 @@
|
|||
.container#recap_info_entreprise
|
||||
%h2 Récapitulatif de vos informations <em id="insee_infogreffe" class='small'>(récupérées auprès de l'INSEE et d'INFOGREFFE)</em>
|
||||
%br
|
||||
#users_siret_index
|
||||
|
||||
.row.etape.etape_1
|
||||
= render partial: '/dossiers/etapes/etape1'
|
||||
|
||||
.row.etape.etape_2
|
||||
= render partial: '/dossiers/etapes/etape2'
|
||||
|
||||
-#- if @facade.procedure.module_api_carto.use_api_carto?
|
||||
-# .row.etape.etape_3
|
||||
-# .etape.etapes_menu.col-md-3.col-lg-3
|
||||
-# %h3
|
||||
-# 3 - Ma zone d'intervention
|
||||
-# .etape.etapes_informations.col-md-9.col-lg-9
|
||||
-#
|
||||
-#.row.etape.etape_4
|
||||
-# .etape.etapes_menu.col-md-3.col-lg-3
|
||||
-# %h3
|
||||
-# = "#{@facade.procedure.module_api_carto.use_api_carto? ? '4' : '3'} - Mon dossier"
|
||||
-# .etape.etapes_informations.col-md-9.col-lg-9
|
||||
|
||||
%div.row
|
||||
= render partial: '/dossiers/infos_entreprise'
|
||||
%br
|
||||
= form_for @facade.dossier, url: { controller: '/users/dossiers', action: :update } do |f|
|
||||
%label{ style:'font-weight:normal' }
|
||||
= f.check_box :autorisation_donnees
|
||||
J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles.
|
||||
%br
|
||||
= f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante'
|
19
app/views/dossiers/etapes/_etape1.html.haml
Normal file
19
app/views/dossiers/etapes/_etape1.html.haml
Normal file
|
@ -0,0 +1,19 @@
|
|||
.etape.etapes_menu.col-md-3.col-lg-3
|
||||
%h3
|
||||
Ma procédure
|
||||
%br
|
||||
.center
|
||||
- if @facade.procedure.euro_flag
|
||||
#euro_flag.flag
|
||||
=image_tag('drapeau_europe.png')
|
||||
|
||||
#logo_procedure.flag
|
||||
=image_tag( @facade.procedure.decorate.logo_img )
|
||||
|
||||
.etape.etapes_informations.col-md-9.col-lg-9
|
||||
.row
|
||||
%h2#titre_procedure.text-info
|
||||
= @facade.procedure.libelle
|
||||
|
||||
%p{style:'width: 95%;'}
|
||||
= h @facade.procedure.description.html_safe
|
39
app/views/dossiers/etapes/_etape2.html.haml
Normal file
39
app/views/dossiers/etapes/_etape2.html.haml
Normal file
|
@ -0,0 +1,39 @@
|
|||
.etape.etapes_menu.col-md-3.col-lg-3
|
||||
%h3
|
||||
Mes informations
|
||||
%br
|
||||
- unless @facade.entreprise.nil?
|
||||
.center{style:'margin-left: -5%'}
|
||||
Vous êtes authentifié avec le SIRET
|
||||
|
||||
%h3.text-success
|
||||
= @facade.etablissement.siret
|
||||
= form_for @facade.dossier, url: users_dossier_change_siret_path(dossier_id: @facade.dossier.id), method: :put, remote: true do |f|
|
||||
= f.submit 'Changer de SIRET', class: %w(btn btn-xs btn-primary)
|
||||
|
||||
|
||||
.etape.etapes_informations.col-md-9.col-lg-9
|
||||
.row
|
||||
- if @facade.entreprise.nil?
|
||||
#new_siret{style:'margin-left: 20%; margin-top: 5%'}
|
||||
= form_for @facade.dossier, html: {class: 'form-inline'}, url: users_dossier_siret_informations_path(dossier_id: @facade.dossier.id), method: :post, remote: true do |f|
|
||||
.form-group.form-group-lg
|
||||
= f.text_field :siret, class: "form-control", placeholder: "Entrez votre Siret", value: @siret
|
||||
= f.hidden_field :dossier_id, value: @facade.dossier.id
|
||||
= f.submit 'Valider', class: %w(btn btn-lg btn-success), data: { disable_with: "Recherche en cours ..." }
|
||||
- else
|
||||
#recap_info_entreprise
|
||||
= render partial: '/dossiers/infos_entreprise'
|
||||
|
||||
%p#insee_infogreffe{style:'color:grey; float:right'}
|
||||
%i
|
||||
Informations récupérées auprès de l'INSEE et d'INFOGREFFE
|
||||
|
||||
%br
|
||||
= form_for @facade.dossier, url: { controller: '/users/dossiers', action: :update } do |f|
|
||||
= f.hidden_field :id
|
||||
%label{ style:'font-weight:normal' }
|
||||
= f.check_box :autorisation_donnees
|
||||
J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles.
|
||||
%br
|
||||
= f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante', disabled: :disabled
|
7
app/views/dossiers/new_siret.js.erb
Normal file
7
app/views/dossiers/new_siret.js.erb
Normal file
|
@ -0,0 +1,7 @@
|
|||
$('.row.etape.etape_2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape2', locals: { facade: @facade } ) %>");
|
||||
the_terms();
|
||||
|
||||
<% unless flash.empty? %>
|
||||
error_form_siret('<%= invalid_siret %>');
|
||||
<% end %>
|
||||
<% flash.clear %>
|
|
@ -1,11 +0,0 @@
|
|||
- if @dossier.procedure.euro_flag
|
||||
#euro_flag.flag
|
||||
=image_tag('drapeau_europe.png')
|
||||
|
||||
#logo_procedure.flag
|
||||
=image_tag( @dossier.procedure.decorate.logo_img )
|
||||
|
||||
%h2#titre_procedure.text-info
|
||||
= @dossier.procedure.libelle
|
||||
%p
|
||||
= h @dossier.procedure.description.html_safe
|
|
@ -1,11 +0,0 @@
|
|||
.container.center#users_siret_index
|
||||
.row
|
||||
%p.lead{id: 'pro_section', style:'padding-top: 120px'}
|
||||
= render partial: 'title_procedure'
|
||||
%br
|
||||
|
||||
= form_for @dossier, url: {controller: 'users/dossiers', action: :create}, method: :post do |f|
|
||||
.form-group.form-group-lg
|
||||
= f.text_field :siret, class: "form-control", placeholder: "Entrez votre Siret", value: @siret
|
||||
= f.hidden_field :procedure_id
|
||||
= f.submit 'Commencer', class: %w(btn btn-lg btn-success), style: 'margin-top:20px;'
|
|
@ -2,7 +2,20 @@
|
|||
%br
|
||||
- if @dossier
|
||||
= link_to 'X', users_no_procedure_url, class: 'btn btn-xs', style:'float: right'
|
||||
= render partial: 'users/dossiers/title_procedure'
|
||||
|
||||
- if @dossier.procedure.euro_flag
|
||||
#euro_flag.flag
|
||||
=image_tag('drapeau_europe.png')
|
||||
|
||||
#logo_procedure.flag
|
||||
=image_tag( @dossier.procedure.decorate.logo_img )
|
||||
|
||||
%h2#titre_procedure.text-info
|
||||
= @dossier.procedure.libelle
|
||||
%p
|
||||
= h @dossier.procedure.description.html_safe
|
||||
|
||||
|
||||
- else
|
||||
= image_tag('logo-tps.png', {id: 'logo_tps'})
|
||||
%br
|
||||
|
|
|
@ -73,6 +73,9 @@ Rails.application.routes.draw do
|
|||
post '/carte' => 'carte#save'
|
||||
|
||||
put '/archive' => 'dossiers#archive'
|
||||
|
||||
post '/siret_informations' => 'dossiers#siret_informations'
|
||||
put '/change_siret' => 'dossiers#change_siret'
|
||||
end
|
||||
resource :dossiers
|
||||
end
|
||||
|
|
|
@ -5,18 +5,20 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
let(:procedure) { create(:procedure, :published) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:siret_not_found) { 999_999_999_999 }
|
||||
|
||||
let(:rna_status) { 404 }
|
||||
let(:rna_body) { '' }
|
||||
|
||||
let(:user) { create :user }
|
||||
|
||||
let(:exercices_status) { 200 }
|
||||
let(:exercices_body) { File.read('spec/support/files/exercices.json') }
|
||||
|
||||
let(:siren) { dossier.siren }
|
||||
let(:siret) { dossier.siret }
|
||||
let(:siren) { '440117620' }
|
||||
let(:siret) { '44011762001530' }
|
||||
let(:siret_with_whitespaces) { '440 1176 2001 530' }
|
||||
let(:bad_siret) { 1 }
|
||||
|
||||
|
@ -55,10 +57,66 @@ describe Users::DossiersController, type: :controller do
|
|||
context 'when procedure_id is valid' do
|
||||
context 'when user is logged in' do
|
||||
before do
|
||||
sign_in create(:user)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { is_expected.to have_http_status(:success) }
|
||||
it { is_expected.to have_http_status(302) }
|
||||
it { is_expected.to redirect_to users_dossier_path(id: Dossier.last) }
|
||||
|
||||
it { expect { subject }.to change(Dossier, :count).by 1 }
|
||||
|
||||
describe 'save user siret' do
|
||||
|
||||
context 'when user have not a saved siret' do
|
||||
context 'when siret is present on request' do
|
||||
subject { get :new, procedure_id: procedure_id, siret: siret }
|
||||
|
||||
before do
|
||||
subject
|
||||
user.reload
|
||||
end
|
||||
|
||||
it { expect(user.siret).to eq siret }
|
||||
end
|
||||
|
||||
context 'when siret is not present on the request' do
|
||||
before do
|
||||
subject
|
||||
user.reload
|
||||
end
|
||||
|
||||
it { expect(user.siret).to eq nil }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user have a saved siret' do
|
||||
before do
|
||||
user.siret = '53029478400026'
|
||||
user.save
|
||||
user.reload
|
||||
end
|
||||
|
||||
context 'when siret is present on request' do
|
||||
subject { get :new, procedure_id: procedure_id, siret: siret }
|
||||
|
||||
before do
|
||||
subject
|
||||
user.reload
|
||||
end
|
||||
|
||||
it { expect(user.siret).to eq siret }
|
||||
end
|
||||
|
||||
context 'when siret is not present on the request' do
|
||||
before do
|
||||
subject
|
||||
user.reload
|
||||
end
|
||||
|
||||
it { expect(user.siret).to eq '53029478400026' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when procedure is archived' do
|
||||
let(:procedure) { create(:procedure, archived: 'true') }
|
||||
|
@ -68,6 +126,7 @@ describe Users::DossiersController, type: :controller do
|
|||
end
|
||||
context 'when user is not logged' do
|
||||
it { is_expected.to have_http_status(302) }
|
||||
it { is_expected.to redirect_to new_user_session_path }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -75,7 +134,7 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:procedure_id) { 0 }
|
||||
|
||||
before do
|
||||
sign_in create(:user)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to users_dossiers_path }
|
||||
|
@ -85,7 +144,7 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:procedure) { create(:procedure, published: false) }
|
||||
|
||||
before do
|
||||
sign_in create(:user)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to users_dossiers_path }
|
||||
|
@ -93,7 +152,7 @@ describe Users::DossiersController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
describe 'POST #siret_informations' do
|
||||
before do
|
||||
stub_request(:get, "https://api-dev.apientreprise.fr/v2/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
|
||||
.to_return(status: 404, body: 'fake body')
|
||||
|
@ -109,6 +168,8 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
stub_request(:get, "https://api-dev.apientreprise.fr/v1/associations/#{siret}?token=#{SIADETOKEN}")
|
||||
.to_return(status: rna_status, body: rna_body)
|
||||
|
||||
dossier
|
||||
end
|
||||
|
||||
describe 'dossier attributs' do
|
||||
|
@ -119,10 +180,10 @@ describe Users::DossiersController, type: :controller do
|
|||
sign_in user
|
||||
end
|
||||
|
||||
subject { post :create, dossier: {siret: example_siret, procedure_id: Procedure.last} }
|
||||
subject { post :siret_informations, dossier_id: dossier.id, dossier: {siret: example_siret} }
|
||||
|
||||
it 'create a dossier' do
|
||||
expect { subject }.to change { Dossier.count }.by(1)
|
||||
expect { subject }.to change { Dossier.count }.by(0)
|
||||
end
|
||||
|
||||
it 'creates entreprise' do
|
||||
|
@ -238,27 +299,32 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
context 'with non existant siret' do
|
||||
before do
|
||||
sign_in create(:user)
|
||||
sign_in user
|
||||
subject
|
||||
end
|
||||
|
||||
let(:siret_not_found) { '11111111111111' }
|
||||
subject { post :create, dossier: {siret: siret_not_found, procedure_id: procedure.id} }
|
||||
subject { post :siret_informations, dossier_id: dossier.id, dossier: {siret: siret_not_found} }
|
||||
|
||||
it 'does not create new dossier' do
|
||||
expect { subject }.not_to change { Dossier.count }
|
||||
end
|
||||
|
||||
it 'redirects to show' do
|
||||
expect(subject).to redirect_to new_users_dossiers_path(procedure_id: procedure_id)
|
||||
end
|
||||
it { expect(response.status).to eq 200 }
|
||||
it { expect(flash.alert).to eq 'Le siret est incorrect' }
|
||||
it { expect(response.to_a[2]).to be_an_instance_of ActionDispatch::Response::RackBody }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
subject { put :update, id: dossier_id, dossier: {id: dossier_id, autorisation_donnees: autorisation_donnees} }
|
||||
|
||||
before do
|
||||
sign_in dossier.user
|
||||
put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees}
|
||||
subject
|
||||
end
|
||||
|
||||
context 'when Checkbox is checked' do
|
||||
let(:autorisation_donnees) { '1' }
|
||||
|
||||
|
@ -272,7 +338,7 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:procedure) { create(:procedure, :with_api_carto) }
|
||||
|
||||
before do
|
||||
put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees}
|
||||
subject
|
||||
end
|
||||
it 'redirects to carte' do
|
||||
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id)
|
||||
|
@ -295,6 +361,25 @@ describe Users::DossiersController, type: :controller do
|
|||
dossier.reload
|
||||
expect(dossier.autorisation_donnees).to be_falsy
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to users_dossier_path(id: dossier.id) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #change_siret' do
|
||||
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
|
||||
|
||||
subject { put :change_siret, dossier_id: dossier.id }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { expect(subject.status).to eq 200 }
|
||||
|
||||
it 'function dossier.reset! is call' do
|
||||
expect_any_instance_of(Dossier).to receive(:reset!)
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
||||
|
|
8
spec/factories/exercice.rb
Normal file
8
spec/factories/exercice.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
FactoryGirl.define do
|
||||
factory :exercice do
|
||||
ca '12345678'
|
||||
dateFinExercice "2014-12-30 23:00:00"
|
||||
date_fin_exercice_timestamp 1419980400
|
||||
association :etablissement, factory: [:etablissement]
|
||||
end
|
||||
end
|
11
spec/factories/rna_information.rb
Normal file
11
spec/factories/rna_information.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
FactoryGirl.define do
|
||||
factory :rna_information do
|
||||
association_id "W072000535"
|
||||
titre "ASSOCIATION POUR LA PROMOTION DE SPECTACLES AU CHATEAU DE ROCHEMAURE"
|
||||
objet "mise en oeuvre et réalisation de spectacles au chateau de rochemaure"
|
||||
date_creation "1990-04-24"
|
||||
date_declaration "2014-11-28"
|
||||
date_publication "1990-05-16"
|
||||
association :entreprise, factory: [:entreprise]
|
||||
end
|
||||
end
|
|
@ -6,7 +6,7 @@ feature 'user path for dossier creation' do
|
|||
let(:siret) { '53272417600013' }
|
||||
let(:siren) { siret[0...9] }
|
||||
|
||||
context 'user arrives on siret page' do
|
||||
context 'user arrives on siret page', js: true do
|
||||
before do
|
||||
visit new_users_dossiers_path(procedure_id: procedure.id)
|
||||
end
|
||||
|
@ -39,11 +39,23 @@ feature 'user path for dossier creation' do
|
|||
.to_return(status: 404, body: '')
|
||||
|
||||
page.find_by_id('dossier_siret').set siret
|
||||
page.click_on 'Commencer'
|
||||
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.check('dossier_autorisation_donnees')
|
||||
|
|
|
@ -6,7 +6,7 @@ feature 'user arrive on siret page' do
|
|||
let(:siret) { '42149333900020' }
|
||||
let(:siren) { siret[0...9] }
|
||||
|
||||
context 'when user is not logged in' do
|
||||
context 'when user is not logged in', js: true do
|
||||
before do
|
||||
visit new_users_dossiers_path(procedure_id: procedure.id)
|
||||
end
|
||||
|
@ -22,7 +22,7 @@ feature 'user arrive on siret page' do
|
|||
end
|
||||
end
|
||||
scenario 'he is redirected to siret page to enter a siret' do
|
||||
expect(page).to have_css('#pro_section')
|
||||
expect(page).to have_css('#new_siret')
|
||||
end
|
||||
context 'when enter a siret' do
|
||||
before do
|
||||
|
@ -36,7 +36,7 @@ feature 'user arrive on siret page' do
|
|||
.to_return(status: 404, body: '')
|
||||
|
||||
page.find_by_id('dossier_siret').set siret
|
||||
page.click_on 'Commencer'
|
||||
page.click_on 'Valider'
|
||||
end
|
||||
scenario 'he is redirected to recap info entreprise page' do
|
||||
expect(page).to have_css('#recap_info_entreprise')
|
||||
|
|
|
@ -563,4 +563,35 @@ describe Dossier do
|
|||
it { expect(subject['entreprise.prenom']).to be_nil }
|
||||
end
|
||||
|
||||
describe '#reset!' do
|
||||
let!(:dossier) { create :dossier, :with_entreprise, autorisation_donnees: true }
|
||||
let!(:rna_information) { create :rna_information, entreprise: dossier.entreprise }
|
||||
let!(:exercice) { create :exercice, etablissement: dossier.etablissement }
|
||||
|
||||
subject { dossier.reset! }
|
||||
|
||||
it { expect(dossier.entreprise).not_to be_nil }
|
||||
it { expect(dossier.etablissement).not_to be_nil }
|
||||
it { expect(dossier.etablissement.exercices).not_to be_empty }
|
||||
it { expect(dossier.etablissement.exercices.size).to eq 1 }
|
||||
it { expect(dossier.entreprise.rna_information).not_to be_nil }
|
||||
it { expect(dossier.autorisation_donnees).to be_truthy }
|
||||
|
||||
it { expect{subject}.to change(RNAInformation, :count).by(-1) }
|
||||
it { expect{subject}.to change(Exercice, :count).by(-1) }
|
||||
|
||||
it { expect{subject}.to change(Entreprise, :count).by(-1) }
|
||||
it { expect{subject}.to change(Etablissement, :count).by(-1) }
|
||||
|
||||
context 'when method reset! is call' do
|
||||
before do
|
||||
subject
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.entreprise).to be_nil }
|
||||
it { expect(dossier.etablissement).to be_nil }
|
||||
it { expect(dossier.autorisation_donnees).to be_falsey }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,7 @@ describe 'dossiers/show.html.haml', type: :view do
|
|||
|
||||
render
|
||||
end
|
||||
|
||||
it 'have autorisation_donnees check box' do
|
||||
expect(rendered).to have_css('#dossier_autorisation_donnees')
|
||||
end
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'users/dossiers/new.html.haml', type: :view, vcr: { cassette_name: 'user_dossier_new_html' } do
|
||||
let(:user) { create(:user) }
|
||||
let(:euro_flag) { false }
|
||||
let(:cerfa_flag) { false }
|
||||
let(:logo) { '' }
|
||||
let(:procedure) { create(:procedure, euro_flag: euro_flag, cerfa_flag: cerfa_flag, logo: logo) }
|
||||
let!(:dossier) { create(:dossier, procedure: procedure, user: user).decorate }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
|
||||
assign(:dossier, dossier.decorate)
|
||||
render
|
||||
end
|
||||
|
||||
subject { rendered }
|
||||
|
||||
it { is_expected.to have_css('#users_siret_index') }
|
||||
|
||||
describe 'euro flag' do
|
||||
context 'euro flag is not present' do
|
||||
it { is_expected.not_to have_css('#euro_flag.flag') }
|
||||
end
|
||||
|
||||
context 'euro flag is present' do
|
||||
let(:euro_flag) { true }
|
||||
it { is_expected.to have_css('#euro_flag.flag') }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'logo procedure' do
|
||||
context 'procedure have no logo' do
|
||||
it 'TPS logo is present' do
|
||||
is_expected.to match(/src="\/assets\/logo-tps-.*\.png"/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'procedure have logo' do
|
||||
# let(:logo) { fixture_file_upload('spec/support/files/logo_test_procedure.png', 'image/png') }
|
||||
let(:logo) { File.new(File.join(::Rails.root.to_s, "/spec/support/files", "logo_test_procedure.png")) }
|
||||
|
||||
it 'Procedure logo is present' do
|
||||
is_expected.to have_css("img[src='#{procedure.logo}']")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue