tech(api-entreprise.etablissement): passage du endpoint ETABLISSEMENT_RESOURCE_NAME en v3
This commit is contained in:
parent
f23a92683e
commit
c90175f121
17 changed files with 359 additions and 201 deletions
|
@ -1,6 +1,6 @@
|
|||
class APIEntreprise::API
|
||||
ENTREPRISE_RESOURCE_NAME = "v3/insee/sirene/unites_legales/%{id}"
|
||||
ETABLISSEMENT_RESOURCE_NAME = "v2/etablissements/%{id}"
|
||||
ETABLISSEMENT_RESOURCE_NAME = "v3/insee/sirene/etablissements/%{id}"
|
||||
EXTRAIT_KBIS_NAME = "v3/infogreffe/rcs/unites_legales/%{id}/extrait_kbis"
|
||||
TVA_NAME = "v3/european_commission/unites_legales/%{id}/numero_tva"
|
||||
EXERCICES_RESOURCE_NAME = "v3/dgfip/etablissements/%{id}/chiffres_affaires"
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
class APIEntreprise::EtablissementAdapter < APIEntreprise::Adapter
|
||||
# Doc Métier : https://entreprise.api.gouv.fr/catalogue/insee/etablissements
|
||||
# Swagger : https://entreprise.api.gouv.fr/developpeurs/openapi#tag/Informations-generales/paths/~1v3~1insee~1sirene~1etablissements~1%7Bsiret%7D/get
|
||||
|
||||
private
|
||||
|
||||
def get_resource
|
||||
|
@ -6,15 +9,26 @@ class APIEntreprise::EtablissementAdapter < APIEntreprise::Adapter
|
|||
end
|
||||
|
||||
def process_params
|
||||
params = data_source[:etablissement].slice(*attr_to_fetch)
|
||||
raw_data = data_source[:data]
|
||||
Sentry.with_scope do |scope|
|
||||
scope.set_tags(siret: @siret)
|
||||
scope.set_extras(source: raw_data)
|
||||
|
||||
if valid_params?(params)
|
||||
adresse_line = params[:adresse].slice(*address_lines_to_fetch).values.compact.join("\r\n")
|
||||
params.merge!(params[:adresse].slice(*address_attr_to_fetch))
|
||||
params[:adresse] = adresse_line
|
||||
params
|
||||
else
|
||||
{}
|
||||
params = raw_data.slice(*attr_to_fetch)
|
||||
params[:naf] = raw_data.dig(:activite_principale, :code)
|
||||
params[:libelle_naf] = raw_data.dig(:activite_principale, :libelle)
|
||||
|
||||
if valid_params?(params)
|
||||
adresse_line = raw_data[:adresse][:acheminement_postal].slice(*address_lines_to_fetch).values.compact.join("\r\n")
|
||||
params.merge!(params[:adresse].slice(*address_attr_to_fetch))
|
||||
params[:nom_voie] = raw_data[:adresse][:libelle_voie]
|
||||
params[:code_insee_localite] = raw_data[:adresse][:code_commune]
|
||||
params[:localite] = raw_data[:adresse][:libelle_commune]
|
||||
params[:adresse] = adresse_line
|
||||
params
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,8 +37,6 @@ class APIEntreprise::EtablissementAdapter < APIEntreprise::Adapter
|
|||
:adresse,
|
||||
:siret,
|
||||
:siege_social,
|
||||
:naf,
|
||||
:libelle_naf,
|
||||
:enseigne,
|
||||
:diffusable_commercialement
|
||||
]
|
||||
|
@ -34,11 +46,8 @@ class APIEntreprise::EtablissementAdapter < APIEntreprise::Adapter
|
|||
[
|
||||
:numero_voie,
|
||||
:type_voie,
|
||||
:nom_voie,
|
||||
:complement_adresse,
|
||||
:code_postal,
|
||||
:localite,
|
||||
:code_insee_localite
|
||||
:code_postal
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ describe Champs::SiretController, type: :controller do
|
|||
|
||||
before do
|
||||
sign_in user
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}/)
|
||||
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siret[0..8]}/)
|
||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
||||
|
@ -134,7 +134,7 @@ describe Champs::SiretController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when the SIRET informations are retrieved successfully' do
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:siret) { '30613890001294' }
|
||||
let(:api_etablissement_status) { 200 }
|
||||
let(:api_etablissement_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
||||
|
||||
|
@ -143,7 +143,7 @@ describe Champs::SiretController, type: :controller do
|
|||
it 'populates the etablissement and SIRET on the model' do
|
||||
champ.reload
|
||||
expect(champ.etablissement.siret).to eq(siret)
|
||||
expect(champ.etablissement.naf).to eq("6202A")
|
||||
expect(champ.etablissement.naf).to eq("8411Z")
|
||||
expect(dossier.reload.etablissement).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -194,7 +194,7 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
before do
|
||||
sign_in(user)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}/)
|
||||
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
||||
.to_return(body: Rails.root.join('spec/fixtures/files/api_entreprise/status.json').read, status: 200)
|
||||
|
|
|
@ -1,53 +1,100 @@
|
|||
{
|
||||
"etablissement": {
|
||||
"adresse": {
|
||||
"cedex": null,
|
||||
"code_insee_localite": "31555",
|
||||
"code_postal": "31400",
|
||||
"complement_adresse": null,
|
||||
"l1": "DIRECTION INTERREGIONALE DES SERVICES PENITENTIAIRES TOULOUSE - SUD",
|
||||
"l2": "SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION, DE LA HAUTE-GARONNE",
|
||||
"l3": null,
|
||||
"l4": "109 AV DE LESPINET",
|
||||
"l5": "BP 4087",
|
||||
"l6": "31400 TOULOUSE",
|
||||
"l7": "FRANCE",
|
||||
"localite": "TOULOUSE",
|
||||
"nom_voie": "DE LESPINET",
|
||||
"numero_voie": "109",
|
||||
"type_voie": "AV"
|
||||
},
|
||||
"commune_implantation": {
|
||||
"code": "31555",
|
||||
"value": "Toulouse"
|
||||
},
|
||||
"date_creation_etablissement": 1458946800,
|
||||
"date_mise_a_jour": 1533648919,
|
||||
"diffusable_commercialement": true,
|
||||
"enseigne": "SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION, DE LA HAUTE-GARONNE",
|
||||
"etat_administratif": {
|
||||
"date_fermeture": null,
|
||||
"value": "A"
|
||||
},
|
||||
"libelle_naf": "Justice",
|
||||
"naf": "8423Z",
|
||||
"pays_implantation": {
|
||||
"code": "FR",
|
||||
"value": "FRANCE"
|
||||
},
|
||||
"region_implantation": {
|
||||
"code": "76",
|
||||
"value": "Occitanie"
|
||||
},
|
||||
"siege_social": false,
|
||||
"siret": "17310120500719",
|
||||
"tranche_effectif_salarie_etablissement": {
|
||||
"a": null,
|
||||
"code": null,
|
||||
"date_reference": null,
|
||||
"de": null,
|
||||
"intitule": null
|
||||
}
|
||||
},
|
||||
"gateway_error": false
|
||||
"data" : {
|
||||
"activite_principale" : {
|
||||
"code" : "84.23Z",
|
||||
"libelle" : "Justice",
|
||||
"nomenclature" : "NAFRev2"
|
||||
},
|
||||
"adresse" : {
|
||||
"acheminement_postal" : {
|
||||
"l1" : "DIRECTION INTERREGIONALE DES SERVICES PENITENTIAIRES TOULOUSE - SUD",
|
||||
"l2" : "",
|
||||
"l3" : "",
|
||||
"l4" : "109 AVENUE DE LESPINET",
|
||||
"l5" : "BP 4087",
|
||||
"l6" : "31400 TOULOUSE",
|
||||
"l7" : "FRANCE"
|
||||
},
|
||||
"code_cedex" : null,
|
||||
"code_commune" : "31555",
|
||||
"code_pays_etranger" : null,
|
||||
"code_postal" : "31400",
|
||||
"complement_adresse" : null,
|
||||
"distribution_speciale" : "BP 4087",
|
||||
"indice_repetition_voie" : null,
|
||||
"libelle_cedex" : null,
|
||||
"libelle_commune" : "TOULOUSE",
|
||||
"libelle_commune_etranger" : null,
|
||||
"libelle_pays_etranger" : null,
|
||||
"libelle_voie" : "DE LESPINET",
|
||||
"numero_voie" : "109",
|
||||
"status_diffusion" : "diffusible",
|
||||
"type_voie" : "AVENUE"
|
||||
},
|
||||
"date_creation" : 1458946800,
|
||||
"date_fermeture" : null,
|
||||
"diffusable_commercialement" : true,
|
||||
"enseigne" : "SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION, DE LA HAUTE-GARONNE",
|
||||
"etat_administratif" : "A",
|
||||
"siege_social" : false,
|
||||
"siret" : "17310120500719",
|
||||
"status_diffusion" : "diffusible",
|
||||
"tranche_effectif_salarie" : {
|
||||
"a" : 99,
|
||||
"code" : "21",
|
||||
"date_reference" : "2020",
|
||||
"de" : 50,
|
||||
"intitule" : "50 à 99 salariés"
|
||||
},
|
||||
"unite_legale" : {
|
||||
"activite_principale" : {
|
||||
"code" : "84.23Z",
|
||||
"libelle" : "Justice",
|
||||
"nomenclature" : "NAFRev2"
|
||||
},
|
||||
"categorie_entreprise" : "ETI",
|
||||
"date_creation" : 362095200,
|
||||
"diffusable_commercialement" : true,
|
||||
"economie_sociale_et_solidaire" : false,
|
||||
"etat_administratif" : "A",
|
||||
"forme_juridique" : {
|
||||
"code" : "7171",
|
||||
"libelle" : "Service déconcentré de l'Ãtat à compétence (inter) régionale"
|
||||
},
|
||||
"personne_morale_attributs" : {
|
||||
"raison_sociale" : "DIRECTION INTERREGIONALE DES SERVICES PENITENTIAIRES TOULOUSE - SUD",
|
||||
"sigle" : "DISP"
|
||||
},
|
||||
"personne_physique_attributs" : {
|
||||
"nom_naissance" : null,
|
||||
"nom_usage" : null,
|
||||
"prenom_1" : null,
|
||||
"prenom_2" : null,
|
||||
"prenom_3" : null,
|
||||
"prenom_4" : null,
|
||||
"prenom_usuel" : null,
|
||||
"pseudonyme" : null,
|
||||
"sexe" : null
|
||||
},
|
||||
"rna" : null,
|
||||
"siren" : "173101205",
|
||||
"siret_siege_social" : "17310120500016",
|
||||
"status_diffusion" : "diffusible",
|
||||
"tranche_effectif_salarie" : {
|
||||
"a" : 4999,
|
||||
"code" : "51",
|
||||
"date_reference" : "2020",
|
||||
"de" : 2000,
|
||||
"intitule" : "2 000 à 4 999 salariés"
|
||||
},
|
||||
"type" : "personne_morale"
|
||||
}
|
||||
},
|
||||
"links" : {
|
||||
"unite_legale" : "https://entreprise.api.gouv.fr/v3/insee/sirene/unites_legales/173101205"
|
||||
},
|
||||
"meta" : {
|
||||
"date_derniere_mise_a_jour" : 1661724000,
|
||||
"redirect_from_siret" : null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +1,99 @@
|
|||
{
|
||||
"etablissement": {
|
||||
"data": {
|
||||
"siret": "30613890001294",
|
||||
"siege_social": true,
|
||||
"siret": "41816609600051",
|
||||
"naf": "6202A",
|
||||
"libelle_naf": "Conseil en systèmes et logiciels informatiques",
|
||||
"date_mise_a_jour": 1449183600,
|
||||
"tranche_effectif_salarie_etablissement": {
|
||||
"de": 200,
|
||||
"a": 249,
|
||||
"code": "31",
|
||||
"date_reference": "2014",
|
||||
"intitule": "200 à 249 salariés"
|
||||
"etat_administratif": "A",
|
||||
"date_fermeture": 1634133818,
|
||||
"activite_principale": {
|
||||
"code": "8411Z",
|
||||
"libelle": "Administration publique générale",
|
||||
"nomenclature": "NAFRev2"
|
||||
},
|
||||
"date_creation_etablissement": 1108594800,
|
||||
"enseigne": null,
|
||||
"region_implantation": {
|
||||
"code": "11",
|
||||
"value": "Île-de-France"
|
||||
},
|
||||
"commune_implantation": {
|
||||
"code": "75108",
|
||||
"value": "PARIS 8"
|
||||
},
|
||||
"pays_implantation": {
|
||||
"code": null,
|
||||
"value": null
|
||||
"tranche_effectif_salarie": {
|
||||
"code": "51",
|
||||
"intitule": "2 000 à 4 999 salariés",
|
||||
"date_reference": "2016",
|
||||
"de": 2000,
|
||||
"a": 4999
|
||||
},
|
||||
"status_diffusion": "diffusible",
|
||||
"diffusable_commercialement": true,
|
||||
"enseigne": "Coiff Land, CoiffureLand",
|
||||
"unite_legale": {
|
||||
"siren": "130025265",
|
||||
"siret_siege_social": "13002526500013",
|
||||
"type": "personne_morale",
|
||||
"personne_morale_attributs": {
|
||||
"raison_sociale": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
|
||||
"sigle": "DINUM"
|
||||
},
|
||||
"personne_physique_attributs": {
|
||||
"pseudonyme": "DJ Falcon",
|
||||
"prenom_usuel": "Jean",
|
||||
"prenom_1": "Jean",
|
||||
"prenom_2": "Jacques",
|
||||
"prenom_3": "Pierre",
|
||||
"prenom_4": "Paul",
|
||||
"nom_usage": "Dupont",
|
||||
"nom_naissance": "Martin",
|
||||
"sexe": "M"
|
||||
},
|
||||
"categorie_entreprise": "GE",
|
||||
"status_diffusion": "diffusible",
|
||||
"diffusable_commercialement": true,
|
||||
"forme_juridique": {
|
||||
"code": "7120",
|
||||
"libelle": "Service central d'un ministère"
|
||||
},
|
||||
"activite_principale": {
|
||||
"code": "8411Z",
|
||||
"libelle": "Administration publique générale",
|
||||
"nomenclature": "NAFRev2"
|
||||
},
|
||||
"tranche_effectif_salarie": {
|
||||
"code": "51",
|
||||
"intitule": "2 000 à 4 999 salariés",
|
||||
"date_reference": "2016",
|
||||
"de": 2000,
|
||||
"a": 4999
|
||||
},
|
||||
"etat_administratif": "A",
|
||||
"economie_sociale_et_solidaire": true,
|
||||
"date_creation": 1634103818
|
||||
},
|
||||
"adresse": {
|
||||
"l1": "OCTO TECHNOLOGY",
|
||||
"l2": null,
|
||||
"l3": null,
|
||||
"l4": "50 AVENUE DES CHAMPS ELYSEES",
|
||||
"l5": null,
|
||||
"l6": "75008 PARIS",
|
||||
"l7": "FRANCE",
|
||||
"numero_voie": "50",
|
||||
"type_voie": "AV",
|
||||
"nom_voie": "DES CHAMPS ELYSEES",
|
||||
"complement_adresse": "complement_adresse",
|
||||
"code_postal": "75008",
|
||||
"localite": "PARIS 8",
|
||||
"code_insee_localite": "75108",
|
||||
"cedex": null
|
||||
}
|
||||
"numero_voie": "22",
|
||||
"indice_repetition_voie": "bis",
|
||||
"type_voie": "RUE",
|
||||
"libelle_voie": "DE LA PAIX",
|
||||
"complement_adresse": "ZAE SAINT GUENAULT",
|
||||
"code_commune": "75112",
|
||||
"code_postal": "75016",
|
||||
"distribution_speciale": "string",
|
||||
"code_cedex": "75590",
|
||||
"libelle_cedex": "PARIS CEDEX 12",
|
||||
"libelle_commune": "PARIS 12",
|
||||
"libelle_commune_etranger": "string",
|
||||
"code_pays_etranger": "99132",
|
||||
"libelle_pays_etranger": "ROYAUME-UNI",
|
||||
"status_diffusion": "diffusible",
|
||||
"acheminement_postal": {
|
||||
"l1": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
|
||||
"l2": "JEAN MARIE DURAND",
|
||||
"l3": "ZAE SAINT GUENAULT",
|
||||
"l4": "51 BIS RUE DE LA PAIX",
|
||||
"l5": "CS 72809",
|
||||
"l6": "75256 PARIX CEDEX 12",
|
||||
"l7": "FRANCE"
|
||||
}
|
||||
},
|
||||
"date_creation": 1634103818
|
||||
},
|
||||
"gateway_error": false
|
||||
"links": {
|
||||
"unite_legale": "https://entreprise.api.gouv.fr/api/v3/insee/unites_legales/130025265"
|
||||
},
|
||||
"meta": {
|
||||
"date_derniere_mise_a_jour": 1618396818,
|
||||
"redirect_from_siret": "30613890000010"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +1,100 @@
|
|||
{
|
||||
"etablissement": {
|
||||
"siege_social": true,
|
||||
"siret": "41816609600051",
|
||||
"naf": "6202A",
|
||||
"libelle_naf": "Conseil en systèmes et logiciels informatiques",
|
||||
"date_mise_a_jour": 1449183600,
|
||||
"tranche_effectif_salarie_etablissement": {
|
||||
"de": 200,
|
||||
"a": 249,
|
||||
"code": "31",
|
||||
"date_reference": "2014",
|
||||
"intitule": "200 à 249 salariés"
|
||||
},
|
||||
"date_creation_etablissement": 1108594800,
|
||||
"enseigne": null,
|
||||
"region_implantation": {
|
||||
"code": "11",
|
||||
"value": "Île-de-France"
|
||||
},
|
||||
"commune_implantation": {
|
||||
"code": "75108",
|
||||
"value": "PARIS 8"
|
||||
},
|
||||
"pays_implantation": {
|
||||
"code": null,
|
||||
"value": null
|
||||
},
|
||||
"diffusable_commercialement": false,
|
||||
"adresse": {
|
||||
"l1": "OCTO TECHNOLOGY",
|
||||
"l2": null,
|
||||
"l3": null,
|
||||
"l4": "50 AVENUE DES CHAMPS ELYSEES",
|
||||
"l5": null,
|
||||
"l6": "75008 PARIS",
|
||||
"l7": "FRANCE",
|
||||
"numero_voie": "50",
|
||||
"type_voie": "AV",
|
||||
"nom_voie": "DES CHAMPS ELYSEES",
|
||||
"complement_adresse": "complement_adresse",
|
||||
"code_postal": "75008",
|
||||
"localite": "PARIS 8",
|
||||
"code_insee_localite": "75108",
|
||||
"cedex": null
|
||||
}
|
||||
},
|
||||
"gateway_error": false
|
||||
"data" : {
|
||||
"activite_principale" : {
|
||||
"code" : "62.02A",
|
||||
"libelle" : "Conseil en systêmes et logiciels informatiques",
|
||||
"nomenclature" : "NAFRev2"
|
||||
},
|
||||
"adresse" : {
|
||||
"acheminement_postal" : {
|
||||
"l1" : "OCTO-TECHNOLOGY",
|
||||
"l2" : "",
|
||||
"l3" : "",
|
||||
"l4" : "50 AVENUE DES CHAMPS ELYSEES",
|
||||
"l5" : "",
|
||||
"l6" : "75008 PARIS 8",
|
||||
"l7" : "FRANCE"
|
||||
},
|
||||
"code_cedex" : null,
|
||||
"code_commune" : "75108",
|
||||
"code_pays_etranger" : null,
|
||||
"code_postal" : "75008",
|
||||
"complement_adresse" : null,
|
||||
"distribution_speciale" : null,
|
||||
"indice_repetition_voie" : null,
|
||||
"libelle_cedex" : null,
|
||||
"libelle_commune" : "PARIS 8",
|
||||
"libelle_commune_etranger" : null,
|
||||
"libelle_pays_etranger" : null,
|
||||
"libelle_voie" : "DES CHAMPS ELYSEES",
|
||||
"numero_voie" : "50",
|
||||
"status_diffusion" : "diffusible",
|
||||
"type_voie" : "AVENUE"
|
||||
},
|
||||
"date_creation" : 1108594800,
|
||||
"date_fermeture" : 1480287600,
|
||||
"diffusable_commercialement" : false,
|
||||
"enseigne" : null,
|
||||
"etat_administratif" : "F",
|
||||
"siege_social" : false,
|
||||
"siret" : "41816609600051",
|
||||
"status_diffusion" : "diffusible",
|
||||
"tranche_effectif_salarie" : {
|
||||
"a" : null,
|
||||
"code" : "NN",
|
||||
"date_reference" : null,
|
||||
"de" : null,
|
||||
"intitule" : "Unités non employeuses"
|
||||
},
|
||||
"unite_legale" : {
|
||||
"activite_principale" : {
|
||||
"code" : "62.02A",
|
||||
"libelle" : "Conseil en systèmes et logiciels informatiques",
|
||||
"nomenclature" : "NAFRev2"
|
||||
},
|
||||
"categorie_entreprise" : "GE",
|
||||
"date_creation" : 891381600,
|
||||
"diffusable_commercialement" : true,
|
||||
"economie_sociale_et_solidaire" : false,
|
||||
"etat_administratif" : "A",
|
||||
"forme_juridique" : {
|
||||
"code" : "5710",
|
||||
"libelle" : "SAS, société par actions simplifiée"
|
||||
},
|
||||
"personne_morale_attributs" : {
|
||||
"raison_sociale" : "OCTO-TECHNOLOGY",
|
||||
"sigle" : null
|
||||
},
|
||||
"personne_physique_attributs" : {
|
||||
"nom_naissance" : null,
|
||||
"nom_usage" : null,
|
||||
"prenom_1" : null,
|
||||
"prenom_2" : null,
|
||||
"prenom_3" : null,
|
||||
"prenom_4" : null,
|
||||
"prenom_usuel" : null,
|
||||
"pseudonyme" : null,
|
||||
"sexe" : null
|
||||
},
|
||||
"rna" : null,
|
||||
"siren" : "418166096",
|
||||
"siret_siege_social" : "41816609600069",
|
||||
"status_diffusion" : "diffusible",
|
||||
"tranche_effectif_salarie" : {
|
||||
"a" : 999,
|
||||
"code" : "41",
|
||||
"date_reference" : "2020",
|
||||
"de" : 500,
|
||||
"intitule" : "500 à 999 salariés"
|
||||
},
|
||||
"type" : "personne_morale"
|
||||
}
|
||||
},
|
||||
"links" : {
|
||||
"unite_legale" : "https://entreprise.api.gouv.fr/v3/insee/sirene/unites_legales/418166096"
|
||||
},
|
||||
"meta" : {
|
||||
"date_derniere_mise_a_jour" : 1538172000,
|
||||
"redirect_from_siret" : null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
RSpec.describe APIEntreprise::ServiceJob, type: :job do
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:siret) { '30613890001294' }
|
||||
let(:service) { create(:service, siret: siret) }
|
||||
let(:entreprise_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
||||
let(:geocoder_body) { File.read('spec/fixtures/files/api_address/address.json') }
|
||||
let(:status) { 200 }
|
||||
|
||||
let (:adresse) { "OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE" }
|
||||
let (:adresse) { "DIRECTION INTERMINISTERIELLE DU NUMERIQUE\r\nJEAN MARIE DURAND\r\nZAE SAINT GUENAULT\r\n51 BIS RUE DE LA PAIX\r\nCS 72809\r\n75256 PARIX CEDEX 12\r\nFRANCE" }
|
||||
|
||||
before do
|
||||
stub_request(:get, %r{https://entreprise.api.gouv.fr/v2/etablissements/})
|
||||
stub_request(:get, %r{https://entreprise.api.gouv.fr/v3\/insee\/sirene\/etablissements\/#{siret}})
|
||||
.to_return(body: entreprise_body, status: status)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
|
||||
|
@ -30,9 +30,9 @@ RSpec.describe APIEntreprise::ServiceJob, type: :job do
|
|||
|
||||
expect(infos).not_to be_empty
|
||||
expect(infos["adresse"]).to eq(adresse)
|
||||
expect(infos["numero_voie"]).to eq("50")
|
||||
expect(infos["code_postal"]).to eq("75008")
|
||||
expect(infos["localite"]).to eq("PARIS 8")
|
||||
expect(infos["numero_voie"]).to eq("22")
|
||||
expect(infos["code_postal"]).to eq("75016")
|
||||
expect(infos["localite"]).to eq("PARIS 12")
|
||||
end
|
||||
|
||||
it "geocode address" do
|
||||
|
@ -45,7 +45,7 @@ RSpec.describe APIEntreprise::ServiceJob, type: :job do
|
|||
|
||||
context "errors responses" do
|
||||
it "clear attributes when no address match" do
|
||||
stub_request(:get, %r{https://entreprise.api.gouv.fr/v2/etablissements/})
|
||||
stub_request(:get, %r{https://entreprise.api.gouv.fr/v3\/insee\/sirene\/etablissements\/#{siret}})
|
||||
.to_return(body: "{}", status: 404)
|
||||
subject
|
||||
service.reload
|
||||
|
|
|
@ -87,7 +87,7 @@ describe APIEntreprise::API do
|
|||
describe '.etablissement' do
|
||||
subject { described_class.new(procedure_id).etablissement(siret) }
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*non_diffusables=true/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}?.*non_diffusables=true/)
|
||||
.to_return(status: status, body: body)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
|
|
@ -7,12 +7,12 @@ describe APIEntreprise::EtablissementAdapter do
|
|||
end
|
||||
|
||||
context 'SIRET valide avec infos diffusables' do
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:siret) { '30613890001294' }
|
||||
let(:fixture) { 'spec/fixtures/files/api_entreprise/etablissements.json' }
|
||||
subject { described_class.new(siret, procedure_id).to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}/)
|
||||
.to_return(body: File.read(fixture, status: 200))
|
||||
end
|
||||
|
||||
|
@ -30,11 +30,11 @@ describe APIEntreprise::EtablissementAdapter do
|
|||
end
|
||||
|
||||
it 'L\'entreprise contient bien un naf' do
|
||||
expect(subject[:naf]).to eq('6202A')
|
||||
expect(subject[:naf]).to eq('8411Z')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un libelle_naf' do
|
||||
expect(subject[:libelle_naf]).to eq('Conseil en systèmes et logiciels informatiques')
|
||||
expect(subject[:libelle_naf]).to eq('Administration publique générale')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un diffusable_commercialement qui vaut true' do
|
||||
|
@ -43,36 +43,37 @@ describe APIEntreprise::EtablissementAdapter do
|
|||
|
||||
context 'Concaténation lignes adresse' do
|
||||
it 'L\'entreprise contient bien une adresse sur plusieurs lignes' do
|
||||
expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE")
|
||||
expect(subject[:adresse]).to eq("DIRECTION INTERMINISTERIELLE DU NUMERIQUE\r\nJEAN MARIE DURAND\r\nZAE SAINT GUENAULT\r\n51 BIS RUE DE LA PAIX\r\nCS 72809\r\n75256 PARIX CEDEX 12\r\nFRANCE")
|
||||
end
|
||||
end
|
||||
|
||||
context 'Détails adresse' do
|
||||
it 'L\'entreprise contient bien un numero_voie' do
|
||||
expect(subject[:numero_voie]).to eq('50')
|
||||
expect(subject[:numero_voie]).to eq('22')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un type_voie' do
|
||||
expect(subject[:type_voie]).to eq('AV')
|
||||
expect(subject[:type_voie]).to eq('RUE')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un nom_voie' do
|
||||
expect(subject[:nom_voie]).to eq('DES CHAMPS ELYSEES')
|
||||
expect(subject[:nom_voie]).to eq('DE LA PAIX')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un complement_adresse' do
|
||||
expect(subject[:complement_adresse]).to eq('complement_adresse')
|
||||
expect(subject[:complement_adresse]).to eq('ZAE SAINT GUENAULT')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un code_postal' do
|
||||
expect(subject[:code_postal]).to eq('75008')
|
||||
expect(subject[:code_postal]).to eq('75016')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien une localite' do
|
||||
expect(subject[:localite]).to eq('PARIS 8')
|
||||
expect(subject[:localite]).to eq('PARIS 12')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un code_insee_localite' do
|
||||
expect(subject[:code_insee_localite]).to eq('75108')
|
||||
expect(subject[:code_insee_localite]).to eq('75112')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -99,7 +100,7 @@ describe APIEntreprise::EtablissementAdapter do
|
|||
subject { described_class.new(siret, procedure_id).to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}/)
|
||||
.to_return(body: File.read('spec/fixtures/files/api_entreprise/etablissements_private.json', status: 200))
|
||||
end
|
||||
|
||||
|
@ -113,7 +114,7 @@ describe APIEntreprise::EtablissementAdapter do
|
|||
subject { described_class.new(bad_siret, procedure_id).to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{bad_siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{bad_siret}/)
|
||||
.to_return(body: 'Fake body', status: 404)
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ describe APIEntreprise::ServiceAdapter do
|
|||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:siret) { '30613890001294' }
|
||||
let(:service) { create(:service, siret: siret) }
|
||||
|
||||
context 'SIRET valide avec infos diffusables' do
|
||||
|
@ -11,7 +11,7 @@ describe APIEntreprise::ServiceAdapter do
|
|||
subject { described_class.new(siret, service.id).to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}/)
|
||||
.with(query: hash_including({ 'object' => "service_id: #{service.id}" }))
|
||||
.to_return(body: File.read(fixture, status: 200))
|
||||
end
|
||||
|
@ -31,36 +31,36 @@ describe APIEntreprise::ServiceAdapter do
|
|||
|
||||
context 'Concaténation lignes adresse' do
|
||||
it 'service contains a multi lines adress' do
|
||||
expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE")
|
||||
expect(subject[:adresse]).to eq("DIRECTION INTERMINISTERIELLE DU NUMERIQUE\r\nJEAN MARIE DURAND\r\nZAE SAINT GUENAULT\r\n51 BIS RUE DE LA PAIX\r\nCS 72809\r\n75256 PARIX CEDEX 12\r\nFRANCE")
|
||||
end
|
||||
end
|
||||
|
||||
context 'adress details' do
|
||||
it 'service contains a numero_voie' do
|
||||
expect(subject[:numero_voie]).to eq('50')
|
||||
expect(subject[:numero_voie]).to eq('22')
|
||||
end
|
||||
|
||||
it 'service contains a type_voie' do
|
||||
expect(subject[:type_voie]).to eq('AV')
|
||||
expect(subject[:type_voie]).to eq('RUE')
|
||||
end
|
||||
|
||||
it 'service contains a nom_voie' do
|
||||
expect(subject[:nom_voie]).to eq('DES CHAMPS ELYSEES')
|
||||
expect(subject[:nom_voie]).to eq('DE LA PAIX')
|
||||
end
|
||||
it 'service contains a complement_adresse' do
|
||||
expect(subject[:complement_adresse]).to eq('complement_adresse')
|
||||
expect(subject[:complement_adresse]).to eq('ZAE SAINT GUENAULT')
|
||||
end
|
||||
|
||||
it 'service contains a code_postal' do
|
||||
expect(subject[:code_postal]).to eq('75008')
|
||||
expect(subject[:code_postal]).to eq('75016')
|
||||
end
|
||||
|
||||
it 'service contains a localite' do
|
||||
expect(subject[:localite]).to eq('PARIS 8')
|
||||
expect(subject[:localite]).to eq('PARIS 12')
|
||||
end
|
||||
|
||||
it 'service contains a code_insee_localite' do
|
||||
expect(subject[:code_insee_localite]).to eq('75108')
|
||||
expect(subject[:code_insee_localite]).to eq('75112')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -79,7 +79,7 @@ describe APIEntreprise::ServiceAdapter do
|
|||
subject { described_class.new(bad_siret, service.id).to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{bad_siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{bad_siret}/)
|
||||
.with(query: hash_including({ 'object' => "service_id: #{service.id}" }))
|
||||
.to_return(body: 'Fake body', status: 404)
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
|
|||
let!(:champ) { create(:champ_siret) }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}/)
|
||||
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siret[0..8]}/)
|
||||
.to_return(body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'), status: 200)
|
||||
|
@ -90,13 +90,13 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
|
|||
end
|
||||
|
||||
context 'when the SIRET informations are retrieved successfully' do
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:siret) { '30613890001294' }
|
||||
let(:api_etablissement_status) { 200 }
|
||||
let(:api_etablissement_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
||||
|
||||
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.siret }.to(siret) }
|
||||
|
||||
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.naf }.to("6202A") }
|
||||
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.naf }.to("8411Z") }
|
||||
|
||||
it { expect { fetch_etablissement! }.to change { Etablissement.count }.by(1) }
|
||||
|
||||
|
|
|
@ -14,13 +14,13 @@ describe APIEntrepriseService do
|
|||
|
||||
describe '#create_etablissement' do
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}/)
|
||||
.to_return(body: etablissements_body, status: etablissements_status)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siret[0..8]}/)
|
||||
.to_return(body: entreprises_body, status: entreprises_status)
|
||||
end
|
||||
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:siret) { '30613890001294' }
|
||||
let(:raison_sociale) { "DIRECTION INTERMINISTERIELLE DU NUMERIQUE" }
|
||||
let(:etablissements_status) { 200 }
|
||||
let(:etablissements_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
||||
|
|
|
@ -7,7 +7,7 @@ shared_examples "the user has got a prefilled dossier, owned by themselves" do
|
|||
click_on 'Valider'
|
||||
|
||||
expect(page).to have_current_path(etablissement_dossier_path(dossier))
|
||||
expect(page).to have_content('OCTO TECHNOLOGY')
|
||||
expect(page).to have_content('DIRECTION INTERMINISTERIELLE DU NUMERIQUE')
|
||||
click_on 'Continuer avec ces informations'
|
||||
|
||||
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
||||
|
|
|
@ -67,7 +67,7 @@ describe 'Creating a new dossier:' do
|
|||
let(:dossier) { procedure.dossiers.last }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret}/)
|
||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
||||
|
@ -96,7 +96,7 @@ describe 'Creating a new dossier:' do
|
|||
click_on 'Valider'
|
||||
|
||||
expect(page).to have_current_path(etablissement_dossier_path(dossier))
|
||||
expect(page).to have_content('OCTO TECHNOLOGY')
|
||||
expect(page).to have_content('Coiff Land, CoiffureLand')
|
||||
click_on 'Continuer avec ces informations'
|
||||
|
||||
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
||||
|
|
|
@ -64,7 +64,7 @@ describe 'Prefilling a dossier (with a GET request):', js: true do
|
|||
}
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\//)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\//)
|
||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
||||
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siret_value[0..8]}/)
|
||||
|
|
|
@ -41,7 +41,7 @@ describe 'Prefilling a dossier (with a POST request):', js: true do
|
|||
let(:annuaire_education_value) { '0050009H' }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret_value}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/etablissements\/#{siret_value}/)
|
||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
||||
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siret_value[0..8]}/)
|
||||
|
|
Loading…
Reference in a new issue