add extrait_kbis to handle nom_commercial and capital_social
This commit is contained in:
parent
ba281d53cf
commit
f04e121a6f
8 changed files with 165 additions and 2 deletions
7
app/jobs/api_entreprise/extrait_kbis_job.rb
Normal file
7
app/jobs/api_entreprise/extrait_kbis_job.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class APIEntreprise::ExtraitKbisJob < APIEntreprise::Job
|
||||
def perform(etablissement_id, procedure_id)
|
||||
find_etablissement(etablissement_id)
|
||||
etablissement_params = APIEntreprise::ExtraitKbisAdapter.new(etablissement.siret, procedure_id).to_params
|
||||
etablissement.update!(etablissement_params)
|
||||
end
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
class APIEntreprise::API
|
||||
ENTREPRISE_RESOURCE_NAME = "v3/insee/sirene/unites_legales/%{id}"
|
||||
ETABLISSEMENT_RESOURCE_NAME = "v2/etablissements/%{id}"
|
||||
EXTRAIT_KBIS_NAME = "v3/infogreffe/rcs/unites_legales/%{id}/extrait_kbis"
|
||||
EXERCICES_RESOURCE_NAME = "v2/exercices/%{id}"
|
||||
RNA_RESOURCE_NAME = "v2/associations/%{id}"
|
||||
EFFECTIFS_RESOURCE_NAME = "v2/effectifs_mensuels_acoss_covid"
|
||||
|
@ -32,6 +33,10 @@ class APIEntreprise::API
|
|||
call_with_siret(ETABLISSEMENT_RESOURCE_NAME, siret)
|
||||
end
|
||||
|
||||
def extrait_kbis(siren)
|
||||
call_with_siret(EXTRAIT_KBIS_NAME, siren)
|
||||
end
|
||||
|
||||
def exercices(siret)
|
||||
call_with_siret(EXERCICES_RESOURCE_NAME, siret)
|
||||
end
|
||||
|
|
17
app/lib/api_entreprise/extrait_kbis_adapter.rb
Normal file
17
app/lib/api_entreprise/extrait_kbis_adapter.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class APIEntreprise::ExtraitKbisAdapter < APIEntreprise::Adapter
|
||||
private
|
||||
|
||||
def get_resource
|
||||
api(@procedure_id).extrait_kbis(siren)
|
||||
end
|
||||
|
||||
def process_params
|
||||
result = {}
|
||||
data = data_source[:data]
|
||||
if data
|
||||
result[:entreprise_capital_social] = data[:capital][:montant] if data[:capital]
|
||||
result[:entreprise_nom_commercial] = data[:nom_commercial]
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
|
@ -47,7 +47,8 @@ class APIEntrepriseService
|
|||
|
||||
def perform_later_fetch_jobs(etablissement, procedure_id, user_id, wait: nil)
|
||||
[
|
||||
APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
|
||||
APIEntreprise::EntrepriseJob, APIEntreprise::ExtraitKbisJob,
|
||||
APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
|
||||
APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob,
|
||||
APIEntreprise::BilansBdfJob
|
||||
].each do |job|
|
||||
|
|
81
spec/fixtures/files/api_entreprise/extrait_kbis.json
vendored
Normal file
81
spec/fixtures/files/api_entreprise/extrait_kbis.json
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
{
|
||||
"data": {
|
||||
"siren": "130025265",
|
||||
"date_radiation": "2019-01-01",
|
||||
"date_extrait": "2022-07-11",
|
||||
"date_immatriculation": "1998-07-12",
|
||||
"mandataires_sociaux": [
|
||||
{
|
||||
"numero_identification": "784824153",
|
||||
"type": "personne_morale",
|
||||
"fonction": "COMMISSAIRE AUX COMPTES SUPPLEANT",
|
||||
"nom": "Henri",
|
||||
"prenom": "Martin",
|
||||
"date_naissance": "1965-01",
|
||||
"raison_sociale": "BCRH & ASSOCIES - SOCIETE A RESPONSABILITE LIMITEE A ASSOCIE UNIQUE"
|
||||
}
|
||||
],
|
||||
"observations": [
|
||||
{
|
||||
"numero": "123456",
|
||||
"libelle": "LA SOCIETE NE CONSERVE AUCUNE ACTIVITE A SON ANCIEN SIEGE",
|
||||
"date": "2000-01-01"
|
||||
}
|
||||
],
|
||||
"nom_commercial": "DECATHLON",
|
||||
"etablissement_principal": {
|
||||
"activite": "dummy",
|
||||
"origine_fonds": "CREATION",
|
||||
"mode_exploitation": "EXPLOITATION DIRECTE",
|
||||
"code_ape": "6420Z"
|
||||
},
|
||||
"capital": {
|
||||
"montant": 50123.6,
|
||||
"devise": "EUROS",
|
||||
"code_devise": "EUR"
|
||||
},
|
||||
"greffe": {
|
||||
"valeur": "COLMAR",
|
||||
"code": "6851"
|
||||
},
|
||||
"personne_physique": {
|
||||
"adresse": {
|
||||
"nom_postal": "22 RUE DE LA PAIX",
|
||||
"numero": "22",
|
||||
"type": "RUE",
|
||||
"voie": "DE LA PAIX",
|
||||
"ligne_1": "dummy",
|
||||
"ligne_2": "dummy",
|
||||
"localite": "dummy",
|
||||
"code_postal": "75016\"",
|
||||
"bureau_distributeur": "dummy",
|
||||
"pays": "FRANCE"
|
||||
},
|
||||
"nationalite": {
|
||||
"valeur": "FRANÇAISE",
|
||||
"code": "FR"
|
||||
},
|
||||
"nom": "MARTIN",
|
||||
"prenom": "JEAN-MARIE",
|
||||
"naissance": {
|
||||
"pays": {
|
||||
"valeur": "FRANCE",
|
||||
"code": "FR"
|
||||
},
|
||||
"date": "1972-01-30",
|
||||
"lieu": "MONTPELLIER"
|
||||
}
|
||||
},
|
||||
"personne_morale": {
|
||||
"forme_juridique": {
|
||||
"valeur": "SOCIETE PAR ACTIONS SIMPLIFIEES",
|
||||
"code": "SASh"
|
||||
},
|
||||
"denomination": "2X INVEST",
|
||||
"date_cloture_exercice_comptable": "02-24",
|
||||
"date_fin_de_vie": "2075-05-18"
|
||||
}
|
||||
},
|
||||
"links": {},
|
||||
"meta": {}
|
||||
}
|
22
spec/jobs/api_entreprise/extrait_kbis_job_spec.rb
Normal file
22
spec/jobs/api_entreprise/extrait_kbis_job_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
describe APIEntreprise::ExtraitKbisJob, type: :job do
|
||||
let(:etablissement) { create(:etablissement, siret: siret) }
|
||||
let(:siret) { '13002526500013' }
|
||||
let(:siren) { '130025265' }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/extrait_kbis.json') }
|
||||
let(:status) { 200 }
|
||||
subject { APIEntreprise::ExtraitKbisJob.new.perform(etablissement.id, procedure_id) }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/infogreffe\/rcs\/unites_legales\/#{siren}\/extrait_kbis/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
it 'updates etablissement' do
|
||||
subject
|
||||
expect(Etablissement.find(etablissement.id).entreprise_capital_social).to eq(50123)
|
||||
expect(Etablissement.find(etablissement.id).entreprise_nom_commercial).to eq('DECATHLON')
|
||||
end
|
||||
end
|
29
spec/lib/api_entreprise/extrait_kbis_adapter_spec.rb
Normal file
29
spec/lib/api_entreprise/extrait_kbis_adapter_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
describe APIEntreprise::ExtraitKbisAdapter do
|
||||
let(:siren) { '130025265' }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:adapter) { described_class.new(siren, procedure_id) }
|
||||
subject { adapter.to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/infogreffe\/rcs\/unites_legales\/#{siren}\/extrait_kbis/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
context "when the SIRET is valid" do
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/extrait_kbis.json') }
|
||||
let(:status) { 200 }
|
||||
|
||||
it '#to_params class est une Hash ?' do
|
||||
expect(subject).to be_an_instance_of(Hash)
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un capital_social' do
|
||||
expect(subject[:entreprise_capital_social]).to eq(50123.6)
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un nom_commercial' do
|
||||
expect(subject[:entreprise_nom_commercial]).to eq('DECATHLON')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,8 @@
|
|||
describe APIEntrepriseService do
|
||||
shared_examples 'schedule fetch of all etablissement params' do
|
||||
[
|
||||
APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
|
||||
APIEntreprise::EntrepriseJob, APIEntreprise::ExtraitKbisJob,
|
||||
APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
|
||||
APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob,
|
||||
APIEntreprise::BilansBdfJob
|
||||
].each do |job|
|
||||
|
|
Loading…
Reference in a new issue