Refactor function create in user dossier controller
This commit is contained in:
parent
5beade4735
commit
65ba614be2
7 changed files with 27 additions and 33 deletions
|
@ -44,24 +44,14 @@ class Users::DossiersController < UsersController
|
|||
procedure_id: create_params[:procedure_id],
|
||||
mandataire_social: mandataire_social?(entreprise_adapter.mandataires_sociaux))
|
||||
|
||||
entreprise = Entreprise.create entreprise_adapter.to_params
|
||||
.merge({dossier_id: dossier.id})
|
||||
entreprise = dossier.create_entreprise(entreprise_adapter.to_params)
|
||||
|
||||
etablissement = Etablissement.create SIADE::EtablissementAdapter.new(siret).to_params
|
||||
.merge({dossier_id: dossier.id,
|
||||
entreprise_id: entreprise.id})
|
||||
entreprise.create_rna_information(SIADE::RNAAdapter.new(siret).to_params)
|
||||
|
||||
rna_information = SIADE::RNAAdapter.new(siret).to_params
|
||||
unless rna_information.nil?
|
||||
RNAInformation.create rna_information.merge({entreprise_id: entreprise.id})
|
||||
end
|
||||
etablissement = dossier.create_etablissement(SIADE::EtablissementAdapter.new(siret).to_params
|
||||
.merge({entreprise_id: entreprise.id}))
|
||||
|
||||
exercices = SIADE::ExercicesAdapter.new(siret).to_params
|
||||
unless exercices.nil?
|
||||
exercices.each_value do |exercice|
|
||||
Exercice.create(exercice.merge({etablissement_id: etablissement.id}))
|
||||
end
|
||||
end
|
||||
etablissement.exercices.create(SIADE::ExercicesAdapter.new(siret).to_params)
|
||||
|
||||
redirect_to url_for(controller: :dossiers, action: :show, id: dossier.id)
|
||||
|
||||
|
@ -167,15 +157,13 @@ class Users::DossiersController < UsersController
|
|||
end
|
||||
|
||||
def mandataire_social? mandataires_list
|
||||
mandataire_social = false
|
||||
|
||||
mandataires_list.each do |mandataire|
|
||||
break mandataire_social = true if !current_user.france_connect_particulier_id.nil? &&
|
||||
return true if !current_user.france_connect_particulier_id.nil? &&
|
||||
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
|
||||
|
||||
mandataire_social
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
class Exercice < ActiveRecord::Base
|
||||
belongs_to :etablissement
|
||||
|
||||
validates :ca, presence: true, allow_blank: false, allow_nil: false
|
||||
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
class RNAInformation < ActiveRecord::Base
|
||||
belongs_to :entreprise
|
||||
|
||||
validates :association_id, presence: true, allow_blank: false, allow_nil: false
|
||||
end
|
||||
|
|
|
@ -10,16 +10,7 @@ class SIADE::ExercicesAdapter
|
|||
end
|
||||
|
||||
def to_params
|
||||
params = {}
|
||||
|
||||
data_source[:exercices].each_with_index do |values, i|
|
||||
params[i] = {}
|
||||
|
||||
values.each do |index, value|
|
||||
params[i][index] = value if attr_to_fetch.include?(index)
|
||||
end
|
||||
end
|
||||
params
|
||||
data_source[:exercices]
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class SIADE::RNAAdapter
|
||||
def initialize(siren)
|
||||
@siret = siren
|
||||
def initialize(siret)
|
||||
@siret = siret
|
||||
end
|
||||
|
||||
def data_source
|
||||
|
|
|
@ -12,6 +12,9 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:rna_status) { 404 }
|
||||
let(:rna_body) { '' }
|
||||
|
||||
let(:exercices_status) { 200 }
|
||||
let(:exercices_body) { File.read('spec/support/files/exercices.json') }
|
||||
|
||||
let(:siren) { dossier.siren }
|
||||
let(:siret) { dossier.siret }
|
||||
let(:bad_siret) { 1 }
|
||||
|
@ -78,7 +81,7 @@ describe Users::DossiersController, type: :controller do
|
|||
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
|
||||
|
||||
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
|
||||
.to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
|
||||
.to_return(status: exercices_status, body: exercices_body)
|
||||
|
||||
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/associations/#{siret}?token=#{SIADETOKEN}")
|
||||
.to_return(status: rna_status, body: rna_body)
|
||||
|
@ -131,6 +134,13 @@ describe Users::DossiersController, type: :controller do
|
|||
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)
|
||||
|
|
|
@ -10,7 +10,7 @@ describe SIADE::ExercicesAdapter do
|
|||
end
|
||||
|
||||
it '#to_params class est une Hash ?' do
|
||||
expect(subject).to be_an_instance_of(Hash)
|
||||
expect(subject).to be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
it 'have 3 exercices' do
|
||||
|
|
Loading…
Reference in a new issue