diff --git a/app/assets/javascripts/old_design/dossiers.js b/app/assets/javascripts/old_design/dossiers.js deleted file mode 100644 index 02092fa12..000000000 --- a/app/assets/javascripts/old_design/dossiers.js +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint no-unused-vars:0 */ -/* globals $ */ - -$(document).on('turbolinks:load', handle_siret_form_errors); - -function error_form_siret(invalid_siret) { - setTimeout(function() { - $("input[type='submit']").val('Erreur SIRET'); - }, 10); - - $("input[type='submit']") - .removeClass('btn-success') - .addClass('btn-danger'); - - $('#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'); -} - -function toggle_etape_1() { - $('.row.etape.etape_1 .etapes-menu #logos').toggle(100); - $('.row.etape.etape_1 .etapes-informations #description_procedure').toggle( - 100 - ); -} - -function handle_siret_form_errors() { - $('.form-inline[data-remote]').on('ajax:error', function(event) { - var input = $('#dossier-siret', event.target); - if (input.length) { - var invalid_siret = input.val(); - error_form_siret(invalid_siret); - } - }); -} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5a4ae2077..37a71f564 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -20,7 +20,6 @@ // = require default_data_block // = require direct_uploads // = require dossiers -// = require etapes // = require france_connect_particulier // = require left_panel // = require login @@ -31,7 +30,6 @@ // = require print // = require procedure // = require search -// = require siret // = require outdated_browser_banner // = require switch_menu // = require autocomplete diff --git a/app/assets/stylesheets/etapes.scss b/app/assets/stylesheets/etapes.scss deleted file mode 100644 index 2ff84fa6f..000000000 --- a/app/assets/stylesheets/etapes.scss +++ /dev/null @@ -1,15 +0,0 @@ -.etape-2 { - .etapes-menu { - #dossier-siret { - width: 200px; - } - - button { - margin-top: 8px; - } - } - - .etapes-informations { - padding-top: 15px; - } -} diff --git a/app/assets/stylesheets/siret.scss b/app/assets/stylesheets/siret.scss deleted file mode 100644 index e5bdf2050..000000000 --- a/app/assets/stylesheets/siret.scss +++ /dev/null @@ -1,12 +0,0 @@ -// Place all the styles related to the start controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ - -.mask { - display: none; -} - -#titre-procedure { - margin-top: 3%; - margin-bottom: 2%; -} diff --git a/app/controllers/users/dossiers/add_siret_controller.rb b/app/controllers/users/dossiers/add_siret_controller.rb deleted file mode 100644 index 9b39f38c8..000000000 --- a/app/controllers/users/dossiers/add_siret_controller.rb +++ /dev/null @@ -1,16 +0,0 @@ -class Users::Dossiers::AddSiretController < ApplicationController - def show - @facade = DossierFacades.new params[:dossier_id], current_user.email - - if !@facade.procedure.individual_with_siret? - raise ActiveRecord::RecordNotFound - end - - if current_user.siret.present? - @siret = current_user.siret - end - rescue ActiveRecord::RecordNotFound - flash.alert = t('errors.messages.dossier_not_found') - redirect_to url_for dossiers_path - end -end diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 06b52f3d2..0a292509b 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -6,7 +6,6 @@ class Users::DossiersController < UsersController before_action :store_user_location!, only: :new before_action :authenticate_user!, except: [:commencer, :commencer_test] - before_action :check_siret, only: :siret_informations before_action only: [:show] do authorized_routes? self.class @@ -52,11 +51,6 @@ class Users::DossiersController < UsersController end dossier = Dossier.create!(procedure: procedure, user: current_user, state: Dossier.states.fetch(:brouillon)) - siret = params[:siret] || current_user.siret - - if siret.present? - update_current_user_siret! siret - end if dossier.procedure.for_individual redirect_to identite_dossier_path(dossier) @@ -67,117 +61,20 @@ class Users::DossiersController < UsersController error_procedure end - def show - @facade = facade - if current_user.siret.present? - @siret = current_user.siret - end - - rescue ActiveRecord::RecordNotFound - flash.alert = t('errors.messages.dossier_not_found') - redirect_to url_for dossiers_path - end - - def siret_informations - @facade = facade params[:dossier_id] - - update_current_user_siret!(siret) - - etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, @facade.dossier.procedure_id) - - if etablissement_attributes.present? - etablissement_attributes = ActionController::Parameters.new(etablissement_attributes).permit! - etablissement = @facade.dossier.build_etablissement(etablissement_attributes) - if !etablissement.save - return errors_valid_siret - end - else - return errors_valid_siret - end - - @facade = facade params[:dossier_id] - - if @facade.procedure.individual_with_siret? - render '/dossiers/add_siret', formats: 'js' - else - render '/dossiers/new_siret', formats: 'js' - end - rescue ActiveRecord::RecordNotFound - flash.alert = t('errors.messages.dossier_not_found') - redirect_to url_for dossiers_path - end - - def change_siret - Dossier.find(params[:dossier_id]).reset! - - @facade = facade params[:dossier_id] - - if @facade.procedure.individual_with_siret? - render '/dossiers/add_siret', formats: 'js' - else - render '/dossiers/new_siret', formats: 'js' - end - end - - def update - @facade = facade params[:dossier][:id] - @facade.dossier.update!(autorisation_donnees: true) - - if @facade.dossier.procedure.module_api_carto.use_api_carto - redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id) - else - redirect_to brouillon_dossier_path(@facade.dossier) - end - end - def self.route_authorization { states: [Dossier.states.fetch(:brouillon)] } end - def destroy - dossier = current_user.dossiers.find(params[:id]) - if dossier.brouillon? - dossier.destroy - flash.notice = 'Brouillon supprimé' - end - redirect_to url_for dossiers_path - end - private - def check_siret - if !Siret.new(siret: siret).valid? - errors_valid_siret - end - end - - def errors_valid_siret - flash.alert = t('errors.messages.invalid_siret') - @facade = facade params[:dossier_id] - - render '/dossiers/new_siret', formats: :js, locals: { invalid_siret: siret } - end - - def siret - create_params[:siret] - end - - def create_params - params.require(:dossier).permit(:siret) - end - def error_procedure flash.alert = t('errors.messages.procedure_not_found') redirect_to url_for dossiers_path end - def update_current_user_siret!(siret) - current_user.update(siret: siret) - end - def facade(id = params[:id]) DossierFacades.new id, current_user.email end diff --git a/app/views/dossiers/_infos_entreprise.html.haml b/app/views/dossiers/_infos_entreprise.html.haml deleted file mode 100644 index a4c5e6311..000000000 --- a/app/views/dossiers/_infos_entreprise.html.haml +++ /dev/null @@ -1,55 +0,0 @@ -.col-md-12.col-sm-12.col-xs-12.col-xs-12 - %h4 - = raison_sociale_or_name(@facade.etablissement) - .row.split-row - .col-xs-12.split-hr -.row - .col-xs-12 - - .row - .col-xs-4.entreprise-label Siret : - .col-xs-8.entreprise-info= @facade.etablissement.siret - - if @facade.etablissement.siret != @facade.etablissement.entreprise.siret_siege_social - .row - .col-xs-4.entreprise-label SIRET siège social : - .col-xs-8.entreprise-info= @facade.etablissement.entreprise.siret_siege_social - .row - .col-xs-4.entreprise-label Forme juridique : - .col-xs-8.entreprise-info= @facade.etablissement.entreprise.forme_juridique - .row - .col-xs-4.entreprise-label Libellé naf : - .col-xs-8.entreprise-info= @facade.etablissement.libelle_naf - .row - .col-xs-4.entreprise-label Code naf : - .col-xs-8.entreprise-info= @facade.etablissement.naf - .row - .col-xs-4.entreprise-label Date de création : - .col-xs-8.entreprise-info= @facade.etablissement.entreprise.date_creation&.strftime("%d-%m-%Y") - .row - .col-xs-4.entreprise-label Effectif organisation : - .col-xs-8.entreprise-info= effectif(@facade.etablissement) - .row - .col-xs-4.entreprise-label Code effectif : - .col-xs-8.entreprise-info= @facade.etablissement.entreprise.code_effectif_entreprise - .row - .col-xs-4.entreprise-label Numéro TVA intracommunautaire : - .col-xs-8.entreprise-info= @facade.etablissement.entreprise.numero_tva_intracommunautaire - - .row - .col-xs-4.entreprise-label Adresse : - .col-xs-8.entreprise-info - - @facade.etablissement.adresse.split("\n").each do |line| - = line - .row - .col-xs-4.entreprise-label Capital social : - .col-xs-8.entreprise-info= pretty_currency(@facade.etablissement.entreprise.capital_social) - - .row - .col-xs-4.entreprise-label Exercices : - .col-xs-8.entreprise-info - les exercices comptables des trois dernières années sont joints à votre dossier. - - .row.split-row - .col-xs-12.split-hr -- if @facade.etablissement.association? - = render partial: '/dossiers/infos_rna' diff --git a/app/views/dossiers/_infos_rna.html.haml b/app/views/dossiers/_infos_rna.html.haml deleted file mode 100644 index b57a2c718..000000000 --- a/app/views/dossiers/_infos_rna.html.haml +++ /dev/null @@ -1,22 +0,0 @@ -.row#infos_rna - .col-lg-6.col-md-6.col-sm-6.col-xs-6 - %dl.dl-horizontal - %dt Association ID : - %dd.text-success= @facade.etablissement.association_rna - - %dt Titre : - %dd= @facade.etablissement.association_titre - - %dt Objet : - %dd= @facade.etablissement.association_objet - - .col-lg-6.col-md-6.col-sm-6.col-xs-6 - %dl.dl-horizontal - %dt Date création : - %dd= @facade.etablissement.association_date_creation&.strftime("%d/%m/%Y") - - %dt Capital publication : - %dd= @facade.etablissement.association_date_publication&.strftime("%d/%m/%Y") - - %dt Capital déclaration : - %dd= @facade.etablissement.association_date_declaration&.strftime("%d/%m/%Y") diff --git a/app/views/dossiers/_pieces_justificatives.html.haml b/app/views/dossiers/_pieces_justificatives.html.haml deleted file mode 100644 index 4d945b685..000000000 --- a/app/views/dossiers/_pieces_justificatives.html.haml +++ /dev/null @@ -1,27 +0,0 @@ -#pieces-justificatives - %table.table - - @facade.dossier.types_de_piece_justificative.order('order_place ASC').each do |type_de_piece_justificative| - %tr{ id: "piece_justificative_#{type_de_piece_justificative.id}" } - %th.col-lg-6 - = type_de_piece_justificative.libelle - %td.col-lg-6.col-md-6.col-sm-6.col-xs-6 - - if type_de_piece_justificative.api_entreprise - %span.text-success Nous l'avons récupéré pour vous. - - elsif (@pj = @facade.dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id)).present? - -# - if user_signed_in? - -# = 'Pièce fournie' - -# - elsif gestionnaire_signed_in? - %a{ href: "#{@pj.content_url}", target: '_blank' } Consulter - %span{ style: 'margin-left: 12px;' } - \- - %a.btn.fa.fa-timer{ style: 'color: black; padding-top: 0;', - "data-target" => "#pj-modal", - "data-toggle" => "modal", - :type => "button", - "data-modal_title" => type_de_piece_justificative.libelle, - "data-modal_index" => "type_de_pj_#{type_de_piece_justificative.id}" } - - else - = 'Pièce non fournie' - - -# - if gestionnaire_signed_in? - = render partial: '/dossiers/modal_historique' diff --git a/app/views/dossiers/_show.html.haml b/app/views/dossiers/_show.html.haml deleted file mode 100644 index 1aa3e24a1..000000000 --- a/app/views/dossiers/_show.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -#users-siret-index - - .row.etape.etape_1 - = render partial: '/dossiers/etapes/etape1' - - .row.etape.etape-2 - = render partial: '/dossiers/etapes/etape2' diff --git a/app/views/dossiers/add_siret.js.erb b/app/views/dossiers/add_siret.js.erb deleted file mode 100644 index d0f81b82e..000000000 --- a/app/views/dossiers/add_siret.js.erb +++ /dev/null @@ -1,12 +0,0 @@ -<% if flash.empty? %> -$('.row.etape.etape-2').hide(300, render_new_siret); -$('.row.etape.etape-2').slideDown(400); -<% else %> -error_form_siret('<%= invalid_siret %>'); -<% end %> - -<% flash.clear %> - -function render_new_siret(){ - $('.row.etape.etape-2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape_2/entreprise', locals: { facade: @facade } ) %>"); -} diff --git a/app/views/dossiers/etapes/_etape1.html.haml b/app/views/dossiers/etapes/_etape1.html.haml deleted file mode 100644 index 9b70619cc..000000000 --- a/app/views/dossiers/etapes/_etape1.html.haml +++ /dev/null @@ -1,23 +0,0 @@ -.col-xs-3.center - %h3 Ma démarche - - #logos.center{ class: (@facade.etablissement.nil? ? '' : 'mask') } - - 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-xs-9 - .row - .col-xs-12.padding-left-30 - %h2#titre-procedure.text-info - = @facade.procedure.libelle - - #description_procedure{ style: 'width: 95%;', class: (@facade.etablissement.nil? ? '' : 'mask') } - = h string_to_html(@facade.procedure.description) - - - if @facade.procedure.lien_site_web.present? - .center - = link_to "En savoir plus ...", sanitize_url(@facade.procedure.lien_site_web), target: '_blank' diff --git a/app/views/dossiers/etapes/_etape2.html.haml b/app/views/dossiers/etapes/_etape2.html.haml deleted file mode 100644 index 4dbf20800..000000000 --- a/app/views/dossiers/etapes/_etape2.html.haml +++ /dev/null @@ -1 +0,0 @@ -= render partial: 'dossiers/etapes/etape_2/entreprise' diff --git a/app/views/dossiers/etapes/_etape3.html.haml b/app/views/dossiers/etapes/_etape3.html.haml deleted file mode 100644 index 4a0e54e99..000000000 --- a/app/views/dossiers/etapes/_etape3.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -.etape.etapes-menu.col-xs-3 - %h3 - Ma zone d'intervention - -.etape.etapes-informations.col-xs-9 - .row diff --git a/app/views/dossiers/etapes/_etape4.html.haml b/app/views/dossiers/etapes/_etape4.html.haml deleted file mode 100644 index 70456b83f..000000000 --- a/app/views/dossiers/etapes/_etape4.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -.etape.etapes-menu.col-xs-3 - %h3 - Mon dossier - -.etape.etapes-informations.col-xs-9 - .row diff --git a/app/views/dossiers/etapes/etape_2/_entreprise.html.haml b/app/views/dossiers/etapes/etape_2/_entreprise.html.haml deleted file mode 100644 index 46af19602..000000000 --- a/app/views/dossiers/etapes/etape_2/_entreprise.html.haml +++ /dev/null @@ -1,36 +0,0 @@ -.etape.etapes-menu.col-xs-3 - %h3 - Mes informations - %br - - if @facade.etablissement.present? - .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-xs-9 - .row - - if @facade.etablissement.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, id: "dossier-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), id: 'submit-siret', data: { disable: true } - - else - %br - #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 - = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float: right;', id: 'etape_suivante' diff --git a/app/views/dossiers/new_siret.js.erb b/app/views/dossiers/new_siret.js.erb deleted file mode 100644 index 7e9ac5949..000000000 --- a/app/views/dossiers/new_siret.js.erb +++ /dev/null @@ -1,13 +0,0 @@ -<% if flash.empty? %> -$('.row.etape.etape-2').hide(300, render_new_siret); -$('.row.etape.etape-2').slideDown(400); -toggle_etape_1(); -<% else %> -error_form_siret('<%= invalid_siret %>'); -<% end %> - -<% flash.clear %> - -function render_new_siret(){ - $('.row.etape.etape-2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape2', locals: { facade: @facade } ) %>"); -} diff --git a/app/views/dossiers/show.html.haml b/app/views/dossiers/show.html.haml deleted file mode 100644 index 8df80b688..000000000 --- a/app/views/dossiers/show.html.haml +++ /dev/null @@ -1 +0,0 @@ -= render partial: 'show' diff --git a/app/views/users/dossiers/add_siret/show.html.haml b/app/views/users/dossiers/add_siret/show.html.haml deleted file mode 100644 index 134d78a16..000000000 --- a/app/views/users/dossiers/add_siret/show.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -.row.etape.etape-2 - = render partial: 'dossiers/etapes/etape_2/entreprise' diff --git a/app/views/users/dossiers/show.html.haml b/app/views/users/dossiers/show.html.haml deleted file mode 100644 index 914452765..000000000 --- a/app/views/users/dossiers/show.html.haml +++ /dev/null @@ -1 +0,0 @@ -= render partial: '/dossiers/show' diff --git a/app/views/users/siret/_pro.html.haml b/app/views/users/siret/_pro.html.haml deleted file mode 100644 index 8221d00e4..000000000 --- a/app/views/users/siret/_pro.html.haml +++ /dev/null @@ -1,14 +0,0 @@ -%p.lead#pro_section - %h2#titre-procedure.text-info - = @procedure.libelle - - %div - = h string_to_html(@procedure.description) - - %br - = form_tag(url_for({ controller: :dossiers, action: :create }), class: 'form-inline', method: 'POST') do |f| - .form-group.form-group-lg - = text_field_tag :siret, nil, :class => "form-control", :placeholder => "Entrez votre Siret", :id => "siret", :name => "siret", :maxlength => 14, :style => 'margin-bottom: 10px', value: @siret - %br - = submit_tag "Commencer", class: %w(btn btn-lg btn-success), style: 'margin-top: 20px;', data: { disable: true, submit: true } - %input{ type: 'hidden', value: "#{@procedure.id}", name: 'procedure_id', id: 'procedure_id' } diff --git a/app/views/users/siret/index.html.haml b/app/views/users/siret/index.html.haml deleted file mode 100644 index c189ce64e..000000000 --- a/app/views/users/siret/index.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -.container.center#users-siret-index - .row - = render partial: 'pro' diff --git a/config/routes.rb b/config/routes.rb index 2a8ebd9f3..8e7faec7f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -150,20 +150,13 @@ Rails.application.routes.draw do end resources :dossiers do - get '/add_siret' => 'dossiers/add_siret#show' - post '/carte/zones' => 'carte#zones' get '/carte' => 'carte#show' post '/carte' => 'carte#save' put '/archive' => 'dossiers#archive' - - post '/siret_informations' => 'dossiers#siret_informations' - put '/change_siret' => 'dossiers#change_siret' end - resource 'dossiers' - # Redirection of legacy "/users/dossiers" route to "/dossiers" get 'dossiers', to: redirect('/dossiers') get 'dossiers/:id/recapitulatif', to: redirect('/dossiers/%{id}') diff --git a/spec/controllers/users/dossiers/add_siret_controller_spec.rb b/spec/controllers/users/dossiers/add_siret_controller_spec.rb deleted file mode 100644 index 9a191b47d..000000000 --- a/spec/controllers/users/dossiers/add_siret_controller_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'spec_helper' - -describe Users::Dossiers::AddSiretController, type: :controller do - describe '#GET show' do - let(:dossier) { create :dossier } - - before do - sign_in dossier.user - end - - subject { get :show, params: { dossier_id: dossier.id } } - - context 'when dossier is not attached at a procedure with individual siret attribut' do - it { is_expected.to redirect_to dossiers_path } - end - - context 'when dossier is attached at a procedure with individual siret attribut' do - let(:procedure) { create :procedure, individual_with_siret: true } - let(:dossier) { create :dossier, procedure: procedure } - - it { expect(subject.status).to eq 200 } - end - end -end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index cac2d12f4..5bfa1dd45 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -7,48 +7,6 @@ describe Users::DossiersController, type: :controller do let(:procedure_id) { procedure.id } 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/fixtures/files/api_entreprise/exercices.json') } - - let(:siren) { '440117620' } - let(:siret) { '44011762001530' } - let(:siret_with_whitespaces) { '440 1176 2001 530' } - let(:bad_siret) { 1 } - - describe 'GET #show' do - before do - sign_in dossier.user - end - it 'returns http success with dossier_id valid' do - get :show, params: { id: dossier_id } - expect(response).to have_http_status(:success) - end - - it 'redirection vers liste dossier si mauvais dossier ID' do - get :show, params: { id: siret_not_found } - expect(response).to redirect_to root_path - end - - describe 'before_action authorized_routes?' do - context 'when dossier does not have a valid state' do - before do - dossier.state = Dossier.states.fetch(:en_instruction) - dossier.save - - get :show, params: { id: dossier.id } - end - - it { is_expected.to redirect_to root_path } - end - end - end describe 'GET #new' do subject { get :new, params: { procedure_id: procedure_id } } @@ -65,58 +23,6 @@ describe Users::DossiersController, type: :controller do 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, params: { 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, params: { 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) } @@ -190,244 +96,4 @@ describe Users::DossiersController, type: :controller do it { expect(subject).to redirect_to(root_path) } end end - - describe 'POST #siret_informations' do - let(:user) { create(:user) } - - before do - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret_not_found}?.*token=/) - .to_return(status: 404, body: 'fake body') - - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/) - .to_return(status: status_entreprise_call, 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: status_entreprise_call, 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: exercices_status, body: exercices_body) - - stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/) - .to_return(status: rna_status, body: rna_body) - - dossier - end - - describe 'dossier attributs' do - let(:status_entreprise_call) { 200 } - shared_examples 'with valid siret' do - before do - sign_in user - end - - subject { post :siret_informations, params: { dossier_id: dossier.id, dossier: { siret: example_siret } } } - - it 'create a dossier' do - expect { subject }.to change { Dossier.count }.by(0) - end - - it "links dossier to user" do - subject - expect(Dossier.last.user).to eq(user) - end - - it 'creates etablissement for dossier' do - expect { subject }.to change { Etablissement.count }.by(1) - end - - it 'links etablissement to dossier' do - subject - expect(Etablissement.last.dossier).to eq(Dossier.last) - end - - it 'links etablissement to entreprise' do - subject - expect(Etablissement.last.entreprise).to be_truthy - end - - it 'creates exercices for dossier' do - expect { subject }.to change { Exercice.count }.by(3) - expect(Exercice.last.etablissement).to eq(Dossier.last.etablissement) - end - - context 'when siret have no exercices' do - let(:exercices_status) { 404 } - let(:exercices_body) { '' } - - it { expect { subject }.not_to change { Exercice.count } } - end - - it 'links procedure to dossier' do - subject - expect(Dossier.last.procedure).to eq(Procedure.last) - end - - it 'state of dossier is brouillon' do - subject - expect(Dossier.last.state).to eq(Dossier.states.fetch(:brouillon)) - end - - describe 'get rna informations' do - context 'when siren have not rna informations' do - let(:rna_status) { 404 } - let(:rna_body) { '' } - - it 'not creates association information for etablissement' do - subject - expect(Dossier.last.etablissement.association?).to be_falsey - end - end - - context 'when siren have rna informations' do - let(:rna_status) { 200 } - let(:rna_body) { File.read('spec/fixtures/files/api_entreprise/associations.json') } - - it 'creates rna information for entreprise' do - subject - expect(Dossier.last.etablissement.association?).to be_truthy - end - end - end - end - - describe "with siret without whitespaces" do - let(:example_siret) { siret } - if ENV['CIRCLECI'].nil? - it_should_behave_like "with valid siret" - end - end - - describe "with siret with whitespaces" do - let(:example_siret) { siret_with_whitespaces } - if ENV['CIRCLECI'].nil? - it_should_behave_like "with valid siret" - end - end - - context 'with non existant siret' do - before do - sign_in user - subject - end - - let(:siret_not_found) { '11111111111111' } - subject { post :siret_informations, params: { 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 { 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 - - context 'when REST error 400 is return' do - let(:status_entreprise_call) { 400 } - - subject { post :siret_informations, params: { dossier_id: dossier.id, dossier: { siret: siret } } } - - before do - sign_in user - subject - end - - it { expect(response.status).to eq 200 } - end - end - - describe 'PUT #update' do - let(:params) { { id: dossier_id, dossier: { id: dossier_id, individual_attributes: individual_params } } } - let(:individual_params) { { gender: 'M.', nom: 'Julien', prenom: 'Xavier', birthdate: birthdate } } - let(:birthdate) { '20/01/1991' } - subject { put :update, params: params } - - before do - sign_in dossier.user - dossier.update_columns(autorisation_donnees: nil) - dossier.reload - subject - end - - context 'when Checkbox is checked' do - context 'procedure not use api carto' do - it 'redirects to demande' do - expect(response).to redirect_to(brouillon_dossier_path(dossier)) - end - end - - context 'procedure use api carto' do - let(:procedure) { create(:procedure, :with_api_carto) } - - before do - subject - end - it 'redirects to carte' do - expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id) - end - end - - it 'update dossier' do - dossier.reload - expect(dossier.autorisation_donnees).to be_truthy - end - end - end - - describe 'DELETE #destroy' do - let(:user) { create(:user) } - let!(:dossier_brouillon) { create :dossier, state: Dossier.states.fetch(:brouillon), user: user } - let!(:dossier_not_brouillon) { create :dossier, state: Dossier.states.fetch(:en_construction), user: user } - - subject { delete :destroy, params: { id: dossier.id } } - - before do - sign_in user - end - - context 'when dossier is brouillon' do - let(:dossier) { dossier_brouillon } - - it { expect(subject.status).to eq 302 } - - describe 'flash notice' do - before do - subject - end - - it { expect(flash[:notice]).to be_present } - end - - it 'destroy dossier is call' do - expect_any_instance_of(Dossier).to receive(:destroy) - subject - end - - it { expect { subject }.to change { Dossier.count }.by(-1) } - end - - context 'when dossier is not a brouillon' do - let(:dossier) { dossier_not_brouillon } - - it { expect { subject }.to change { Dossier.count }.by(0) } - end - end - - describe 'PUT #change_siret' do - let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } - - subject { put :change_siret, params: { 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 end diff --git a/spec/views/dossiers/_infos_entreprise_spec.rb b/spec/views/dossiers/_infos_entreprise_spec.rb deleted file mode 100644 index 5d723b8e8..000000000 --- a/spec/views/dossiers/_infos_entreprise_spec.rb +++ /dev/null @@ -1 +0,0 @@ -# TODO à écrire diff --git a/spec/views/dossiers/show.html.haml_spec.rb b/spec/views/dossiers/show.html.haml_spec.rb deleted file mode 100644 index 43d75fdd6..000000000 --- a/spec/views/dossiers/show.html.haml_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'spec_helper' - -describe 'dossiers/show.html.haml', type: :view do - let(:user) { create(:user) } - let(:dossier) { create(:dossier, :with_entreprise, user: user) } - - before do - assign(:facade, DossierFacades.new(dossier.id, user.email)) - - render - end - - context "sur la page d'information d'un SIRET" do - it 'Le formulaire envoie vers /users/dossiers/:dossier_id en #POST' do - expect(rendered).to have_selector("form[action='/users/dossiers'][method=post]") - end - - it "les informations de l'entreprise sont présents" do - expect(rendered).to have_content('Siret') - end - - it 'le bouton "Etape suivante" est présent' do - expect(rendered).to have_selector('#etape_suivante') - end - end -end diff --git a/spec/views/users/siret/index.html.haml_spec.rb b/spec/views/users/siret/index.html.haml_spec.rb deleted file mode 100644 index 34d6ff893..000000000 --- a/spec/views/users/siret/index.html.haml_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'spec_helper' - -describe 'users/siret/index.html.haml', type: :view do - let(:procedure) { create(:procedure, libelle: 'Demande de subvention') } - before do - assign(:procedure, procedure) - render - end - - it 'la section des professionnels est présente' do - expect(rendered).to have_selector('#pro_section') - end - - context 'dans la section professionnel' do - it 'le formulaire envoie vers /dossiers en #POST' do - expect(rendered).to have_selector("form[action='/users/dossiers'][method=post]") - end - - it 'le champs "Numéro SIRET" est présent' do - expect(rendered).to have_selector('input[id=siret][name=siret]') - end - - it 'le titre de la démarche' do - expect(rendered).to have_selector('#titre-procedure') - end - - context 'stockage de l\'ID de la démarche dans un champs hidden' do - it { expect(rendered).to have_selector("input[type=hidden][id=procedure_id][name=procedure_id][value='#{procedure.id}']", visible: false) } - end - - it 'le titre de la démarche est présent sur la page' do - expect(rendered).to have_content(procedure.libelle) - end - end -end