migrate entreprise adapter to v3

This commit is contained in:
Christophe Robillard 2023-05-25 11:15:26 +02:00
parent 14ec64ef6d
commit ba281d53cf
14 changed files with 168 additions and 341 deletions

View file

@ -1,5 +1,5 @@
class APIEntreprise::API
ENTREPRISE_RESOURCE_NAME = "v2/entreprises/%{id}"
ENTREPRISE_RESOURCE_NAME = "v3/insee/sirene/unites_legales/%{id}"
ETABLISSEMENT_RESOURCE_NAME = "v2/etablissements/%{id}"
EXERCICES_RESOURCE_NAME = "v2/exercices/%{id}"
RNA_RESOURCE_NAME = "v2/associations/%{id}"

View file

@ -6,7 +6,7 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
end
def process_params
params = data_source[:entreprise]
params = data_source[:data]
return {} if params.nil?
Sentry.with_scope do |scope|
@ -18,9 +18,29 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
if params.present? && valid_params?(params)
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
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}" }
else
{}
@ -28,49 +48,34 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
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
[
:siren,
:capital_social,
:numero_tva_intracommunautaire,
:forme_juridique,
:forme_juridique_code,
:nom_commercial,
:personne_morale_attributs,
:personne_physique_attributs,
:raison_sociale,
:siret_siege_social,
:code_effectif_entreprise,
:date_creation,
:nom,
:prenom
:tranche_effectif_salarie,
:date_creation
]
end
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
when 'A' then 'actif'
when 'F', 'C' then 'fermé'
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

View file

@ -31,7 +31,7 @@ describe Champs::SiretController, type: :controller do
sign_in user
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
.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'))
allow_any_instance_of(APIEntrepriseToken).to receive(:roles)
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])

View file

@ -196,7 +196,7 @@ describe Users::DossiersController, type: :controller do
sign_in(user)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
.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)
allow_any_instance_of(APIEntrepriseToken).to receive(:roles)
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])

View file

@ -1,86 +1,53 @@
{
"entreprise": {
"data": {
"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",
"code_effectif_entreprise": null,
"date_creation": 1643151600,
"nom": "LE LOUARN",
"prenom": "MARINE",
"date_radiation": null,
"categorie_entreprise": null,
"tranche_effectif_salarie_entreprise": {
"de": null,
"a": null,
"code": null,
"date_reference": null,
"intitule": null
"type": "personne_physique",
"personne_morale_attributs": {
"raison_sociale": null,
"sigle": null
},
"mandataires_sociaux": [],
"etat_administratif": {
"value": "A",
"date_cessation": null
},
"diffusable_commercialement": true
},
"etablissement_siege": {
"siege_social": true,
"siret": "90970089000025",
"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"
"personne_physique_attributs": {
"pseudonyme": null,
"prenom_usuel": "MARINE",
"prenom_1": "MARINE",
"prenom_2": null,
"prenom_3": null,
"prenom_4": null,
"nom_usage": "LE LOUARN SMAIL",
"nom_naissance": "LE LOUARN",
"sexe": "F"
},
"diffusable_commercialement": true,
"enseigne": null,
"adresse": {
"l1": "MADAME MARINE LE LOUARN SMAIL",
"l2": null,
"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
"status_diffusion": "diffusible",
"forme_juridique": {
"code": "1000",
"libelle": "Entrepreneur individuel"
},
"etat_administratif": {
"value": "A",
"date_fermeture": null
}
"activite_principale": {
"code": "71.12B",
"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
}
}

View file

@ -1,187 +1,53 @@
{
"entreprise": {
"siren": "418166096",
"capital_social": 462308,
"numero_tva_intracommunautaire": "FR16418166096",
"forme_juridique": "SA à directoire (s.a.i.)",
"forme_juridique_code": "5699",
"nom_commercial": "OCTO-TECHNOLOGY",
"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"
"data": {
"siren": "130025265",
"siret_siege_social": "13002526500013",
"type": "personne_morale",
"personne_morale_attributs": {
"raison_sociale": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE",
"sigle": "DINUM"
},
"etat_administratif": {
"value": "A",
"date_cessation": null
"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": "Dubois",
"sexe": "M"
},
"exercices": [
{
"chiffre_affaires": null,
"date_fin": null,
"date_debut": null,
"date_fin_exercice_timestamp": null
},
{
"chiffre_affaires": null,
"date_fin": null,
"date_debut": null,
"date_fin_exercice_timestamp": null
},
{
"chiffre_affaires": null,
"date_fin": null,
"date_debut": null,
"date_fin_exercice_timestamp": null
}
],
"mandataires_sociaux": [
{
"nom": "HISQUIN",
"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"
}
]
"categorie_entreprise": "GE",
"status_diffusion": "lorem",
"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,
"date_cessation": 1634133818
},
"etablissement_siege": {
"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": 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
}
"links": {
"siege_social": "https://entreprises.api.gouv.fr/api/v3/insee/etablissements/30613890001294",
"siege_social_adresse": "https://entreprises.api.gouv.fr/api/v3/insee/etablissements/30613890001294/adresse"
},
"gateway_error": false
"meta": {
"date_derniere_mise_a_jour": 1618396818,
"redirect_from_siren": "306138900"
}
}

View file

@ -8,7 +8,7 @@ RSpec.describe APIEntreprise::EntrepriseJob, type: :job do
let(:status) { 200 }
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)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
@ -17,7 +17,7 @@ RSpec.describe APIEntreprise::EntrepriseJob, type: :job do
it 'updates etablissement' do
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
it 'convert entreprise etat_administratif source to an enum' do

View file

@ -7,8 +7,8 @@ describe APIEntreprise::API do
subject { described_class.new(procedure_id).entreprise(siren) }
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
.to_return(status: status, body: body)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
.to_return(body: body, status: status)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
@ -68,7 +68,7 @@ describe APIEntreprise::API do
it 'call api-entreprise with specfic token' do
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
@ -78,7 +78,7 @@ describe APIEntreprise::API do
it 'call api-entreprise with specfic token' do
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

View file

@ -1,12 +1,12 @@
describe APIEntreprise::EntrepriseAdapter do
let(:siren) { '418166096' }
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\/v2\/entreprises\/#{siren}/)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
.to_return(body: body, status: status)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
@ -24,48 +24,28 @@ describe APIEntreprise::EntrepriseAdapter do
expect(subject[:entreprise_siren]).to eq(siren)
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
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
it 'L\'entreprise contient bien un forme_juridique_code' do
expect(subject[:entreprise_forme_juridique_code]).to eq('5699')
end
it 'L\'entreprise contient bien un nom_commercial' do
expect(subject[:entreprise_nom_commercial]).to eq('OCTO-TECHNOLOGY')
expect(subject[:entreprise_forme_juridique_code]).to eq('7120')
end
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
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
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
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')
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')
expect(subject[:entreprise_date_creation].to_i).to eq(1634103818)
end
it 'L\'entreprise contient bien un etat administratif' do
@ -76,7 +56,7 @@ describe APIEntreprise::EntrepriseAdapter do
context "when date_creation is empty" do
let(:body) do
hash = JSON.parse(super())
hash["entreprise"]["date_creation"] = nil
hash["data"]["date_creation"] = nil
JSON.generate(hash)
end
@ -109,14 +89,23 @@ describe APIEntreprise::EntrepriseAdapter do
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprise_individual.json') }
let(:status) { 200 }
context 'Attributs Entreprises' do
it 'L\'entreprise contient bien un forme_juridique_code' do
expect(subject[:entreprise_forme_juridique_code]).to eq('1000')
end
it 'L\'entreprise contient bien un forme_juridique_code' do
expect(subject[:entreprise_forme_juridique_code]).to eq('1000')
end
it 'L\'entreprise contient bien une raison_sociale' do
expect(subject[:entreprise_raison_sociale]).to eq('Marine LE LOUARN SMAIL (LE LOUARN)')
end
# Suppression du champ raison_sociale pour les personnes physiques
# en v3
# 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

View file

@ -8,7 +8,7 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
.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)
allow_any_instance_of(APIEntrepriseToken).to receive(:roles)
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])
@ -104,7 +104,7 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
it "fetches the entreprise raison sociale" do
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

View file

@ -15,12 +15,12 @@ describe APIEntrepriseService do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
.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)
end
let(:siret) { '41816609600051' }
let(:raison_sociale) { "OCTO-TECHNOLOGY" }
let(:raison_sociale) { "DIRECTION INTERMINISTERIELLE DU NUMERIQUE" }
let(:etablissements_status) { 200 }
let(:etablissements_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
let(:entreprises_status) { 200 }

View file

@ -70,7 +70,7 @@ describe 'Creating a new dossier:' do
before do
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'))
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'))
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'))

View file

@ -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\//)
.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'))
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)

View file

@ -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}/)
.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'))
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)