migrate entreprise adapter to v3
This commit is contained in:
parent
14ec64ef6d
commit
ba281d53cf
14 changed files with 168 additions and 341 deletions
|
@ -1,5 +1,5 @@
|
||||||
class APIEntreprise::API
|
class APIEntreprise::API
|
||||||
ENTREPRISE_RESOURCE_NAME = "v2/entreprises/%{id}"
|
ENTREPRISE_RESOURCE_NAME = "v3/insee/sirene/unites_legales/%{id}"
|
||||||
ETABLISSEMENT_RESOURCE_NAME = "v2/etablissements/%{id}"
|
ETABLISSEMENT_RESOURCE_NAME = "v2/etablissements/%{id}"
|
||||||
EXERCICES_RESOURCE_NAME = "v2/exercices/%{id}"
|
EXERCICES_RESOURCE_NAME = "v2/exercices/%{id}"
|
||||||
RNA_RESOURCE_NAME = "v2/associations/%{id}"
|
RNA_RESOURCE_NAME = "v2/associations/%{id}"
|
||||||
|
|
|
@ -6,7 +6,7 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_params
|
def process_params
|
||||||
params = data_source[:entreprise]
|
params = data_source[:data]
|
||||||
return {} if params.nil?
|
return {} if params.nil?
|
||||||
|
|
||||||
Sentry.with_scope do |scope|
|
Sentry.with_scope do |scope|
|
||||||
|
@ -18,9 +18,29 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
|
||||||
|
|
||||||
if params.present? && valid_params?(params)
|
if params.present? && valid_params?(params)
|
||||||
params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime if params[:date_creation].present?
|
params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime if params[:date_creation].present?
|
||||||
if params[:raison_sociale].present? && is_individual_entreprise?(params[:forme_juridique_code])
|
|
||||||
params[:raison_sociale] = humanize_raison_sociale(params[:raison_sociale])
|
forme_juridique = params.extract! :forme_juridique
|
||||||
|
if forme_juridique.present?
|
||||||
|
params[:forme_juridique] = forme_juridique[:forme_juridique][:libelle]
|
||||||
|
params[:forme_juridique_code] = forme_juridique[:forme_juridique][:code]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
personne_morale_attributs = params.extract! :personne_morale_attributs
|
||||||
|
if personne_morale_attributs.present?
|
||||||
|
params[:raison_sociale] = personne_morale_attributs[:personne_morale_attributs][:raison_sociale]
|
||||||
|
end
|
||||||
|
|
||||||
|
personne_physique_attributs = params.extract! :personne_physique_attributs
|
||||||
|
if personne_physique_attributs.present?
|
||||||
|
params[:nom] = build_nom(personne_physique_attributs)
|
||||||
|
params[:prenom] = personne_physique_attributs[:personne_physique_attributs][:prenom_usuel]
|
||||||
|
end
|
||||||
|
|
||||||
|
tranche_effectif = params.extract! :tranche_effectif_salarie
|
||||||
|
if tranche_effectif.present?
|
||||||
|
params[:code_effectif_entreprise] = tranche_effectif[:tranche_effectif_salarie][:code]
|
||||||
|
end
|
||||||
|
|
||||||
params.transform_keys { |k| :"entreprise_#{k}" }
|
params.transform_keys { |k| :"entreprise_#{k}" }
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
|
@ -28,49 +48,34 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_nom(personne_physique_attributs)
|
||||||
|
nom_usage = personne_physique_attributs[:personne_physique_attributs][:nom_usage]&.strip
|
||||||
|
nom_naissance = personne_physique_attributs[:personne_physique_attributs][:nom_naissance]&.strip
|
||||||
|
|
||||||
|
return nom_usage if nom_naissance.blank? || nom_usage == nom_naissance
|
||||||
|
return nom_naissance if nom_usage.blank?
|
||||||
|
"#{nom_usage} (#{nom_naissance})"
|
||||||
|
end
|
||||||
|
|
||||||
def attr_to_fetch
|
def attr_to_fetch
|
||||||
[
|
[
|
||||||
:siren,
|
:siren,
|
||||||
:capital_social,
|
|
||||||
:numero_tva_intracommunautaire,
|
|
||||||
:forme_juridique,
|
:forme_juridique,
|
||||||
:forme_juridique_code,
|
:personne_morale_attributs,
|
||||||
:nom_commercial,
|
:personne_physique_attributs,
|
||||||
:raison_sociale,
|
:raison_sociale,
|
||||||
:siret_siege_social,
|
:siret_siege_social,
|
||||||
:code_effectif_entreprise,
|
:tranche_effectif_salarie,
|
||||||
:date_creation,
|
:date_creation
|
||||||
:nom,
|
|
||||||
:prenom
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def map_etat_administratif(data_source)
|
def map_etat_administratif(data_source)
|
||||||
raw_value = data_source.dig(:entreprise, :etat_administratif, :value) # data structure will change in v3
|
raw_value = data_source.dig(:data, :etat_administratif) # data structure will change in v3
|
||||||
|
|
||||||
case raw_value
|
case raw_value
|
||||||
when 'A' then 'actif'
|
when 'A' then 'actif'
|
||||||
when 'F', 'C' then 'fermé'
|
when 'F', 'C' then 'fermé'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def humanize_raison_sociale(params_raison_sociale)
|
|
||||||
# see SIREN official spec : https://sirene.fr/sirene/public/variable/syr-nomen-long
|
|
||||||
splitted_raison_sociale = params_raison_sociale.split(/[*,\/]/)
|
|
||||||
|
|
||||||
nom_patronymique = splitted_raison_sociale.first
|
|
||||||
prenom = splitted_raison_sociale.last.titleize.strip
|
|
||||||
|
|
||||||
if splitted_raison_sociale.count == 3
|
|
||||||
nom_usage = splitted_raison_sociale.second
|
|
||||||
raison_sociale = "#{prenom} #{nom_usage} (#{nom_patronymique})"
|
|
||||||
else
|
|
||||||
raison_sociale = "#{prenom} #{nom_patronymique}"
|
|
||||||
end
|
|
||||||
raison_sociale
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_individual_entreprise?(forme_juridique_code)
|
|
||||||
forme_juridique_code == "1000"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe Champs::SiretController, type: :controller do
|
||||||
sign_in user
|
sign_in user
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||||
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siret[0..8]}/)
|
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'))
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
||||||
allow_any_instance_of(APIEntrepriseToken).to receive(:roles)
|
allow_any_instance_of(APIEntrepriseToken).to receive(:roles)
|
||||||
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])
|
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])
|
||||||
|
|
|
@ -196,7 +196,7 @@ describe Users::DossiersController, type: :controller do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||||
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
|
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)
|
.to_return(body: Rails.root.join('spec/fixtures/files/api_entreprise/status.json').read, status: 200)
|
||||||
allow_any_instance_of(APIEntrepriseToken).to receive(:roles)
|
allow_any_instance_of(APIEntrepriseToken).to receive(:roles)
|
||||||
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])
|
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])
|
||||||
|
|
|
@ -1,86 +1,53 @@
|
||||||
{
|
{
|
||||||
"entreprise": {
|
"data": {
|
||||||
"siren": "909700890",
|
"siren": "909700890",
|
||||||
"capital_social": null,
|
|
||||||
"numero_tva_intracommunautaire": "FR19909700890",
|
|
||||||
"forme_juridique": "Entrepreneur individuel",
|
|
||||||
"forme_juridique_code": "1000",
|
|
||||||
"nom_commercial": "",
|
|
||||||
"procedure_collective": false,
|
|
||||||
"enseigne": null,
|
|
||||||
"libelle_naf_entreprise": "Ingénierie, études techniques",
|
|
||||||
"naf_entreprise": "7112B",
|
|
||||||
"raison_sociale": "LE LOUARN*LE LOUARN SMAIL/MARINE /",
|
|
||||||
"siret_siege_social": "90970089000025",
|
"siret_siege_social": "90970089000025",
|
||||||
"code_effectif_entreprise": null,
|
|
||||||
"date_creation": 1643151600,
|
|
||||||
"nom": "LE LOUARN",
|
|
||||||
"prenom": "MARINE",
|
|
||||||
"date_radiation": null,
|
|
||||||
"categorie_entreprise": null,
|
"categorie_entreprise": null,
|
||||||
"tranche_effectif_salarie_entreprise": {
|
"type": "personne_physique",
|
||||||
"de": null,
|
"personne_morale_attributs": {
|
||||||
"a": null,
|
"raison_sociale": null,
|
||||||
"code": null,
|
"sigle": null
|
||||||
"date_reference": null,
|
|
||||||
"intitule": null
|
|
||||||
},
|
},
|
||||||
"mandataires_sociaux": [],
|
"personne_physique_attributs": {
|
||||||
"etat_administratif": {
|
"pseudonyme": null,
|
||||||
"value": "A",
|
"prenom_usuel": "MARINE",
|
||||||
"date_cessation": null
|
"prenom_1": "MARINE",
|
||||||
},
|
"prenom_2": null,
|
||||||
"diffusable_commercialement": true
|
"prenom_3": null,
|
||||||
},
|
"prenom_4": null,
|
||||||
"etablissement_siege": {
|
"nom_usage": "LE LOUARN SMAIL",
|
||||||
"siege_social": true,
|
"nom_naissance": "LE LOUARN",
|
||||||
"siret": "90970089000025",
|
"sexe": "F"
|
||||||
"naf": "7112B",
|
|
||||||
"libelle_naf": "Ingénierie, études techniques",
|
|
||||||
"date_mise_a_jour": 1657592059,
|
|
||||||
"tranche_effectif_salarie_etablissement": {
|
|
||||||
"de": null,
|
|
||||||
"a": null,
|
|
||||||
"code": null,
|
|
||||||
"date_reference": null,
|
|
||||||
"intitule": null
|
|
||||||
},
|
|
||||||
"date_creation_etablissement": 1646694000,
|
|
||||||
"region_implantation": {
|
|
||||||
"code": "84",
|
|
||||||
"value": "Auvergne-Rhône-Alpes"
|
|
||||||
},
|
|
||||||
"commune_implantation": {
|
|
||||||
"code": "42218",
|
|
||||||
"value": "Saint-Étienne"
|
|
||||||
},
|
|
||||||
"pays_implantation": {
|
|
||||||
"code": "FR",
|
|
||||||
"value": "FRANCE"
|
|
||||||
},
|
},
|
||||||
"diffusable_commercialement": true,
|
"diffusable_commercialement": true,
|
||||||
"enseigne": null,
|
"status_diffusion": "diffusible",
|
||||||
"adresse": {
|
"forme_juridique": {
|
||||||
"l1": "MADAME MARINE LE LOUARN SMAIL",
|
"code": "1000",
|
||||||
"l2": null,
|
"libelle": "Entrepreneur individuel"
|
||||||
"l3": null,
|
|
||||||
"l4": "4 RUE ETIENNE MIMARD",
|
|
||||||
"l5": null,
|
|
||||||
"l6": "42000 SAINT-ETIENNE",
|
|
||||||
"l7": "FRANCE",
|
|
||||||
"numero_voie": "4",
|
|
||||||
"type_voie": "RUE",
|
|
||||||
"nom_voie": "ETIENNE MIMARD",
|
|
||||||
"complement_adresse": null,
|
|
||||||
"code_postal": "42000",
|
|
||||||
"localite": "SAINT-ETIENNE",
|
|
||||||
"code_insee_localite": "42218",
|
|
||||||
"cedex": null
|
|
||||||
},
|
},
|
||||||
"etat_administratif": {
|
"activite_principale": {
|
||||||
"value": "A",
|
"code": "71.12B",
|
||||||
"date_fermeture": null
|
"nomenclature": "NAFRev2",
|
||||||
}
|
"libelle": "Ingénierie, études techniques"
|
||||||
|
},
|
||||||
|
"tranche_effectif_salarie": {
|
||||||
|
"de": null,
|
||||||
|
"a": null,
|
||||||
|
"code": null,
|
||||||
|
"date_reference": null,
|
||||||
|
"intitule": null
|
||||||
|
},
|
||||||
|
"etat_administratif": "A",
|
||||||
|
"economie_sociale_et_solidaire": null,
|
||||||
|
"date_cessation": null,
|
||||||
|
"date_creation": 1643151600
|
||||||
},
|
},
|
||||||
"gateway_error": false
|
"links": {
|
||||||
|
"siege_social": "https://entreprise.api.gouv.fr/v3/insee/sirene/etablissements/90970089000025",
|
||||||
|
"siege_social_adresse": "https://entreprise.api.gouv.fr/v3/insee/sirene/etablissements/90970089000025/adresse"
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"date_derniere_mise_a_jour": 1657576800,
|
||||||
|
"redirect_from_siren": null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
228
spec/fixtures/files/api_entreprise/entreprises.json
vendored
228
spec/fixtures/files/api_entreprise/entreprises.json
vendored
|
@ -1,187 +1,53 @@
|
||||||
{
|
{
|
||||||
"entreprise": {
|
"data": {
|
||||||
"siren": "418166096",
|
"siren": "130025265",
|
||||||
"capital_social": 462308,
|
"siret_siege_social": "13002526500013",
|
||||||
"numero_tva_intracommunautaire": "FR16418166096",
|
"type": "personne_morale",
|
||||||
"forme_juridique": "SA à directoire (s.a.i.)",
|
"personne_morale_attributs": {
|
||||||
"forme_juridique_code": "5699",
|
"raison_sociale": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
|
||||||
"nom_commercial": "OCTO-TECHNOLOGY",
|
"sigle": "DINUM"
|
||||||
"procedure_collective": false,
|
|
||||||
"raison_sociale": "OCTO-TECHNOLOGY",
|
|
||||||
"siret_siege_social": "41816609600051",
|
|
||||||
"code_effectif_entreprise": "31",
|
|
||||||
"date_creation": 891381600,
|
|
||||||
"nom": "test_nom",
|
|
||||||
"prenom": "test_prenom",
|
|
||||||
"date_radiation": null,
|
|
||||||
"categorie_entreprise": "PME",
|
|
||||||
"tranche_effectif_salarie_entreprise": {
|
|
||||||
"de": 200,
|
|
||||||
"a": 249,
|
|
||||||
"code": "31",
|
|
||||||
"date_reference": "2014",
|
|
||||||
"intitule": "200 à 249 salariés"
|
|
||||||
},
|
},
|
||||||
"etat_administratif": {
|
"personne_physique_attributs": {
|
||||||
"value": "A",
|
"pseudonyme": "DJ Falcon",
|
||||||
"date_cessation": null
|
"prenom_usuel": "Jean",
|
||||||
|
"prenom_1": "Jean",
|
||||||
|
"prenom_2": "Jacques",
|
||||||
|
"prenom_3": "Pierre",
|
||||||
|
"prenom_4": "Paul",
|
||||||
|
"nom_usage": "Dupont",
|
||||||
|
"nom_naissance": "Dubois",
|
||||||
|
"sexe": "M"
|
||||||
},
|
},
|
||||||
"exercices": [
|
"categorie_entreprise": "GE",
|
||||||
{
|
"status_diffusion": "lorem",
|
||||||
"chiffre_affaires": null,
|
"diffusable_commercialement": true,
|
||||||
"date_fin": null,
|
"forme_juridique": {
|
||||||
"date_debut": null,
|
"code": "7120",
|
||||||
"date_fin_exercice_timestamp": null
|
"libelle": "Service central d'un ministère"
|
||||||
},
|
},
|
||||||
{
|
"activite_principale": {
|
||||||
"chiffre_affaires": null,
|
"code": "8411Z",
|
||||||
"date_fin": null,
|
"libelle": "Administration publique générale",
|
||||||
"date_debut": null,
|
"nomenclature": "NAFRev2"
|
||||||
"date_fin_exercice_timestamp": null
|
},
|
||||||
},
|
"tranche_effectif_salarie": {
|
||||||
{
|
"code": "51",
|
||||||
"chiffre_affaires": null,
|
"intitule": "2 000 à 4 999 salariés",
|
||||||
"date_fin": null,
|
"date_reference": "2016",
|
||||||
"date_debut": null,
|
"de": 2000,
|
||||||
"date_fin_exercice_timestamp": null
|
"a": 4999
|
||||||
}
|
},
|
||||||
],
|
"etat_administratif": "A",
|
||||||
"mandataires_sociaux": [
|
"economie_sociale_et_solidaire": true,
|
||||||
{
|
"date_creation": 1634103818,
|
||||||
"nom": "HISQUIN",
|
"date_cessation": 1634133818
|
||||||
"prenom": "FRANCOIS",
|
|
||||||
"fonction": "PRESIDENT DU DIRECTOIRE",
|
|
||||||
"dirigeant": true,
|
|
||||||
"date_naissance": "1965-01-27",
|
|
||||||
"date_naissance_timestamp": -155523600,
|
|
||||||
"raison_sociale": "",
|
|
||||||
"identifiant": "",
|
|
||||||
"type": "PP"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"nom": "BONTE",
|
|
||||||
"prenom": "NICOLAS",
|
|
||||||
"fonction": "PRESIDENT DU CONSEIL DE SURVEILLANCE",
|
|
||||||
"dirigeant": true,
|
|
||||||
"date_naissance": "1965-01-21",
|
|
||||||
"date_naissance_timestamp": -156042000,
|
|
||||||
"raison_sociale": "",
|
|
||||||
"identifiant": "",
|
|
||||||
"type": "PP"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"nom": "BOSQUE",
|
|
||||||
"prenom": "WILLIAM",
|
|
||||||
"fonction": "VICE PRESIDENT ET MEMBRE DU CONSEIL DE SURVEILLANCE",
|
|
||||||
"dirigeant": true,
|
|
||||||
"date_naissance": "1970-12-31",
|
|
||||||
"date_naissance_timestamp": 31446000,
|
|
||||||
"raison_sociale": "",
|
|
||||||
"identifiant": "",
|
|
||||||
"type": "PP"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"nom": "CINQUIN",
|
|
||||||
"prenom": "LUDOVIC",
|
|
||||||
"fonction": "MEMBRE DU DIRECTOIRE",
|
|
||||||
"dirigeant": true,
|
|
||||||
"date_naissance": "1972-01-25",
|
|
||||||
"date_naissance_timestamp": 65142000,
|
|
||||||
"raison_sociale": "",
|
|
||||||
"identifiant": "",
|
|
||||||
"type": "PP"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"nom": "LUCAS",
|
|
||||||
"prenom": "JACQUES",
|
|
||||||
"fonction": "MEMBRE DU CONSEIL DE SURVEILLANCE",
|
|
||||||
"dirigeant": true,
|
|
||||||
"date_naissance": "1964-12-02",
|
|
||||||
"date_naissance_timestamp": -160362000,
|
|
||||||
"raison_sociale": "",
|
|
||||||
"identifiant": "",
|
|
||||||
"type": "PP"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"nom": "DEGONSE",
|
|
||||||
"prenom": "GERARD",
|
|
||||||
"fonction": "MEMBRE DU CONSEIL DE SURVEILLANCE",
|
|
||||||
"dirigeant": true,
|
|
||||||
"date_naissance": "1947-07-03",
|
|
||||||
"date_naissance_timestamp": -710038800,
|
|
||||||
"raison_sociale": "",
|
|
||||||
"identifiant": "",
|
|
||||||
"type": "PP"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"nom": "PLANTIN",
|
|
||||||
"prenom": "JEAN-FRANCOIS",
|
|
||||||
"fonction": "COMMISSAIRE AUX COMPTES TITULAIRE",
|
|
||||||
"dirigeant": true,
|
|
||||||
"date_naissance": "1959-01-27",
|
|
||||||
"date_naissance_timestamp": -344912400,
|
|
||||||
"raison_sociale": "",
|
|
||||||
"identifiant": "",
|
|
||||||
"type": "PP"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"nom": "",
|
|
||||||
"prenom": "",
|
|
||||||
"fonction": "COMMISSAIRE AUX COMPTES SUPPLEANT",
|
|
||||||
"dirigeant": true,
|
|
||||||
"date_naissance": "",
|
|
||||||
"date_naissance_timestamp": 0,
|
|
||||||
"raison_sociale": "BCRH \u0026 ASSOCIES - SOCIETE A RESPONSABILITE LIMITEE A ASSOCIE UNIQUE",
|
|
||||||
"identifiant": "490092574",
|
|
||||||
"type": "PM"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"etablissement_siege": {
|
"links": {
|
||||||
"siege_social": true,
|
"siege_social": "https://entreprises.api.gouv.fr/api/v3/insee/etablissements/30613890001294",
|
||||||
"siret": "41816609600051",
|
"siege_social_adresse": "https://entreprises.api.gouv.fr/api/v3/insee/etablissements/30613890001294/adresse"
|
||||||
"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": null,
|
|
||||||
"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": null,
|
|
||||||
"code_postal": "75008",
|
|
||||||
"localite": "PARIS 8",
|
|
||||||
"code_insee_localite": "75108",
|
|
||||||
"cedex": null
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"gateway_error": false
|
"meta": {
|
||||||
|
"date_derniere_mise_a_jour": 1618396818,
|
||||||
|
"redirect_from_siren": "306138900"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ RSpec.describe APIEntreprise::EntrepriseJob, type: :job do
|
||||||
let(:status) { 200 }
|
let(:status) { 200 }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
||||||
.to_return(body: body, status: status)
|
.to_return(body: body, status: status)
|
||||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ RSpec.describe APIEntreprise::EntrepriseJob, type: :job do
|
||||||
|
|
||||||
it 'updates etablissement' do
|
it 'updates etablissement' do
|
||||||
subject
|
subject
|
||||||
expect(Etablissement.find(etablissement.id).entreprise_numero_tva_intracommunautaire).to eq('FR16418166096')
|
expect(Etablissement.find(etablissement.id).entreprise_raison_sociale).to eq("DIRECTION INTERMINISTERIELLE DU NUMERIQUE")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'convert entreprise etat_administratif source to an enum' do
|
it 'convert entreprise etat_administratif source to an enum' do
|
||||||
|
|
|
@ -7,8 +7,8 @@ describe APIEntreprise::API do
|
||||||
subject { described_class.new(procedure_id).entreprise(siren) }
|
subject { described_class.new(procedure_id).entreprise(siren) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
||||||
.to_return(status: status, body: body)
|
.to_return(body: body, status: status)
|
||||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ describe APIEntreprise::API do
|
||||||
|
|
||||||
it 'call api-entreprise with specfic token' do
|
it 'call api-entreprise with specfic token' do
|
||||||
subject
|
subject
|
||||||
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
|
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ describe APIEntreprise::API do
|
||||||
|
|
||||||
it 'call api-entreprise with specfic token' do
|
it 'call api-entreprise with specfic token' do
|
||||||
subject
|
subject
|
||||||
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
|
expect(WebMock).to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
describe APIEntreprise::EntrepriseAdapter do
|
describe APIEntreprise::EntrepriseAdapter do
|
||||||
let(:siren) { '418166096' }
|
let(:siren) { '130025265' }
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
let(:procedure_id) { procedure.id }
|
let(:procedure_id) { procedure.id }
|
||||||
let(:adapter) { described_class.new(siren, procedure_id) }
|
let(:adapter) { described_class.new(siren, procedure_id) }
|
||||||
subject { adapter.to_params }
|
subject { adapter.to_params }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
||||||
.to_return(body: body, status: status)
|
.to_return(body: body, status: status)
|
||||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||||
end
|
end
|
||||||
|
@ -24,48 +24,28 @@ describe APIEntreprise::EntrepriseAdapter do
|
||||||
expect(subject[:entreprise_siren]).to eq(siren)
|
expect(subject[:entreprise_siren]).to eq(siren)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'L\'entreprise contient bien un capital_social' do
|
|
||||||
expect(subject[:entreprise_capital_social]).to eq(462308)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'L\'entreprise contient bien un numero_tva_intracommunautaire' do
|
|
||||||
expect(subject[:entreprise_numero_tva_intracommunautaire]).to eq('FR16418166096')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'L\'entreprise contient bien une forme_juridique' do
|
it 'L\'entreprise contient bien une forme_juridique' do
|
||||||
expect(subject[:entreprise_forme_juridique]).to eq('SA à directoire (s.a.i.)')
|
expect(subject[:entreprise_forme_juridique]).to eq("Service central d'un ministère")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'L\'entreprise contient bien un forme_juridique_code' do
|
it 'L\'entreprise contient bien un forme_juridique_code' do
|
||||||
expect(subject[:entreprise_forme_juridique_code]).to eq('5699')
|
expect(subject[:entreprise_forme_juridique_code]).to eq('7120')
|
||||||
end
|
|
||||||
|
|
||||||
it 'L\'entreprise contient bien un nom_commercial' do
|
|
||||||
expect(subject[:entreprise_nom_commercial]).to eq('OCTO-TECHNOLOGY')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'L\'entreprise contient bien une raison_sociale' do
|
it 'L\'entreprise contient bien une raison_sociale' do
|
||||||
expect(subject[:entreprise_raison_sociale]).to eq('OCTO-TECHNOLOGY')
|
expect(subject[:entreprise_raison_sociale]).to eq('DIRECTION INTERMINISTERIELLE DU NUMERIQUE')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'L\'entreprise contient bien un siret_siege_social' do
|
it 'L\'entreprise contient bien un siret_siege_social' do
|
||||||
expect(subject[:entreprise_siret_siege_social]).to eq('41816609600051')
|
expect(subject[:entreprise_siret_siege_social]).to eq('13002526500013')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'L\'entreprise contient bien un code_effectif_entreprise' do
|
it 'L\'entreprise contient bien un code_effectif_entreprise' do
|
||||||
expect(subject[:entreprise_code_effectif_entreprise]).to eq('31')
|
expect(subject[:entreprise_code_effectif_entreprise]).to eq('51')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'L\'entreprise contient bien une date_creation' do
|
it 'L\'entreprise contient bien une date_creation' do
|
||||||
expect(subject[:entreprise_date_creation]).to eq('Wed, 01 Apr 1998 00:00:00.000000000 +0200')
|
expect(subject[:entreprise_date_creation].to_i).to eq(1634103818)
|
||||||
end
|
|
||||||
|
|
||||||
it 'L\'entreprise contient bien un nom' do
|
|
||||||
expect(subject[:entreprise_nom]).to eq('test_nom')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'L\'entreprise contient bien un prenom' do
|
|
||||||
expect(subject[:entreprise_prenom]).to eq('test_prenom')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'L\'entreprise contient bien un etat administratif' do
|
it 'L\'entreprise contient bien un etat administratif' do
|
||||||
|
@ -76,7 +56,7 @@ describe APIEntreprise::EntrepriseAdapter do
|
||||||
context "when date_creation is empty" do
|
context "when date_creation is empty" do
|
||||||
let(:body) do
|
let(:body) do
|
||||||
hash = JSON.parse(super())
|
hash = JSON.parse(super())
|
||||||
hash["entreprise"]["date_creation"] = nil
|
hash["data"]["date_creation"] = nil
|
||||||
JSON.generate(hash)
|
JSON.generate(hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -109,14 +89,23 @@ describe APIEntreprise::EntrepriseAdapter do
|
||||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprise_individual.json') }
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprise_individual.json') }
|
||||||
let(:status) { 200 }
|
let(:status) { 200 }
|
||||||
|
|
||||||
context 'Attributs Entreprises' do
|
it 'L\'entreprise contient bien un forme_juridique_code' do
|
||||||
it 'L\'entreprise contient bien un forme_juridique_code' do
|
expect(subject[:entreprise_forme_juridique_code]).to eq('1000')
|
||||||
expect(subject[:entreprise_forme_juridique_code]).to eq('1000')
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it 'L\'entreprise contient bien une raison_sociale' do
|
# Suppression du champ raison_sociale pour les personnes physiques
|
||||||
expect(subject[:entreprise_raison_sociale]).to eq('Marine LE LOUARN SMAIL (LE LOUARN)')
|
# en v3
|
||||||
end
|
# https://entreprise.api.gouv.fr/developpeurs/guide-migration
|
||||||
|
it 'L\'entreprise ne contient pas de raison_sociale' do
|
||||||
|
expect(subject[:entreprise_raison_sociale]).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'L\'entreprise contient bien un nom' do
|
||||||
|
expect(subject[:entreprise_nom]).to eq('LE LOUARN SMAIL (LE LOUARN)')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'L\'entreprise contient bien un prenom' do
|
||||||
|
expect(subject[:entreprise_prenom]).to eq('MARINE')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
|
||||||
before do
|
before do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||||
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siret[0..8]}/)
|
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)
|
.to_return(body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'), status: 200)
|
||||||
allow_any_instance_of(APIEntrepriseToken).to receive(:roles)
|
allow_any_instance_of(APIEntrepriseToken).to receive(:roles)
|
||||||
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])
|
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])
|
||||||
|
@ -104,7 +104,7 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
|
||||||
|
|
||||||
it "fetches the entreprise raison sociale" do
|
it "fetches the entreprise raison sociale" do
|
||||||
fetch_etablissement!
|
fetch_etablissement!
|
||||||
expect(champ.reload.etablissement.entreprise_raison_sociale).to eq("OCTO-TECHNOLOGY")
|
expect(champ.reload.etablissement.entreprise_raison_sociale).to eq("DIRECTION INTERMINISTERIELLE DU NUMERIQUE")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,12 +15,12 @@ describe APIEntrepriseService do
|
||||||
before do
|
before do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||||
.to_return(body: etablissements_body, status: etablissements_status)
|
.to_return(body: etablissements_body, status: etablissements_status)
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siret[0..8]}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siret[0..8]}/)
|
||||||
.to_return(body: entreprises_body, status: entreprises_status)
|
.to_return(body: entreprises_body, status: entreprises_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:siret) { '41816609600051' }
|
let(:siret) { '41816609600051' }
|
||||||
let(:raison_sociale) { "OCTO-TECHNOLOGY" }
|
let(:raison_sociale) { "DIRECTION INTERMINISTERIELLE DU NUMERIQUE" }
|
||||||
let(:etablissements_status) { 200 }
|
let(:etablissements_status) { 200 }
|
||||||
let(:etablissements_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
let(:etablissements_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
||||||
let(:entreprises_status) { 200 }
|
let(:entreprises_status) { 200 }
|
||||||
|
|
|
@ -70,7 +70,7 @@ describe 'Creating a new dossier:' do
|
||||||
before do
|
before do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
|
||||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
|
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'))
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/#{siret}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/#{siret}/)
|
||||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/exercices.json'))
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/exercices.json'))
|
||||||
|
|
|
@ -67,7 +67,7 @@ describe 'Prefilling a dossier (with a GET request):', js: true do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\//)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\//)
|
||||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
||||||
|
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siret_value[0..8]}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siret_value[0..8]}/)
|
||||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
||||||
|
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
|
||||||
|
|
|
@ -44,7 +44,7 @@ describe 'Prefilling a dossier (with a POST request):', js: true do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret_value}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret_value}/)
|
||||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
|
||||||
|
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siret_value[0..8]}/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siret_value[0..8]}/)
|
||||||
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
|
||||||
|
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
|
||||||
|
|
Loading…
Reference in a new issue