Merge pull request #9092 from demarches-simplifiees/8472-migrate-entreprise-tva-kbis
Api Entreprise : Migration Entreprise Tva et Kbis
This commit is contained in:
commit
abc230c57f
26 changed files with 450 additions and 349 deletions
7
app/jobs/api_entreprise/extrait_kbis_job.rb
Normal file
7
app/jobs/api_entreprise/extrait_kbis_job.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class APIEntreprise::ExtraitKbisJob < APIEntreprise::Job
|
||||
def perform(etablissement_id, procedure_id)
|
||||
find_etablissement(etablissement_id)
|
||||
etablissement_params = APIEntreprise::ExtraitKbisAdapter.new(etablissement.siret, procedure_id).to_params
|
||||
etablissement.update!(etablissement_params)
|
||||
end
|
||||
end
|
7
app/jobs/api_entreprise/tva_job.rb
Normal file
7
app/jobs/api_entreprise/tva_job.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class APIEntreprise::TvaJob < APIEntreprise::Job
|
||||
def perform(etablissement_id, procedure_id)
|
||||
find_etablissement(etablissement_id)
|
||||
etablissement_params = APIEntreprise::TvaAdapter.new(etablissement.siret, procedure_id).to_params
|
||||
etablissement.update!(etablissement_params)
|
||||
end
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
class APIEntreprise::API
|
||||
ENTREPRISE_RESOURCE_NAME = "v2/entreprises/%{id}"
|
||||
ENTREPRISE_RESOURCE_NAME = "v3/insee/sirene/unites_legales/%{id}"
|
||||
ETABLISSEMENT_RESOURCE_NAME = "v2/etablissements/%{id}"
|
||||
EXTRAIT_KBIS_NAME = "v3/infogreffe/rcs/unites_legales/%{id}/extrait_kbis"
|
||||
TVA_NAME = "v3/european_commission/unites_legales/%{id}/numero_tva"
|
||||
EXERCICES_RESOURCE_NAME = "v2/exercices/%{id}"
|
||||
RNA_RESOURCE_NAME = "v2/associations/%{id}"
|
||||
EFFECTIFS_RESOURCE_NAME = "v2/effectifs_mensuels_acoss_covid"
|
||||
|
@ -32,6 +34,14 @@ class APIEntreprise::API
|
|||
call_with_siret(ETABLISSEMENT_RESOURCE_NAME, siret)
|
||||
end
|
||||
|
||||
def extrait_kbis(siren)
|
||||
call_with_siret(EXTRAIT_KBIS_NAME, siren)
|
||||
end
|
||||
|
||||
def tva(siren)
|
||||
call_with_siret(TVA_NAME, siren)
|
||||
end
|
||||
|
||||
def exercices(siret)
|
||||
call_with_siret(EXERCICES_RESOURCE_NAME, siret)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
class APIEntreprise::AttestationSocialeAdapter < APIEntreprise::Adapter
|
||||
# Doc métier : https://entreprise.api.gouv.fr/catalogue/urssaf/attestation_vigilance
|
||||
# Swagger : https://entreprise.api.gouv.fr/developpeurs/openapi#tag/Attestations-sociales-et-fiscales/paths/~1v4~1urssaf~1unites_legales~1%7Bsiren%7D~1attestation_vigilance/get
|
||||
|
||||
def initialize(siret, procedure_id)
|
||||
@siret = siret
|
||||
@procedure_id = procedure_id
|
||||
|
@ -11,12 +14,19 @@ class APIEntreprise::AttestationSocialeAdapter < APIEntreprise::Adapter
|
|||
end
|
||||
|
||||
def process_params
|
||||
if data_source[:data] && data_source[:data][:document_url].present?
|
||||
{
|
||||
entreprise_attestation_sociale_url: data_source[:data][:document_url]
|
||||
}
|
||||
else
|
||||
{}
|
||||
data = data_source[:data]
|
||||
|
||||
Sentry.with_scope do |scope|
|
||||
scope.set_tags(siret: @siret)
|
||||
scope.set_extras(source: data)
|
||||
|
||||
if data && data[:document_url].present?
|
||||
{
|
||||
entreprise_attestation_sociale_url: data[:document_url]
|
||||
}
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
|
||||
# Doc métier : https://entreprise.api.gouv.fr/catalogue/insee/unites_legales
|
||||
# Swagger : https://entreprise.api.gouv.fr/developpeurs/openapi#tag/Informations-generales/paths/~1v3~1insee~1sirene~1unites_legales~1%7Bsiren%7D/get
|
||||
|
||||
private
|
||||
|
||||
def get_resource
|
||||
|
@ -6,7 +9,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 +21,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 +51,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
|
||||
|
|
25
app/lib/api_entreprise/extrait_kbis_adapter.rb
Normal file
25
app/lib/api_entreprise/extrait_kbis_adapter.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
class APIEntreprise::ExtraitKbisAdapter < APIEntreprise::Adapter
|
||||
# Doc métier : https://entreprise.api.gouv.fr/catalogue/infogreffe/rcs/extrait
|
||||
# Swagger : https://entreprise.api.gouv.fr/developpeurs/openapi#tag/Informations-generales/paths/~1v3~1infogreffe~1rcs~1unites_legales~1%7Bsiren%7D~1extrait_kbis/get
|
||||
|
||||
private
|
||||
|
||||
def get_resource
|
||||
api(@procedure_id).extrait_kbis(siren)
|
||||
end
|
||||
|
||||
def process_params
|
||||
result = {}
|
||||
data = data_source[:data]
|
||||
|
||||
Sentry.with_scope do |scope|
|
||||
scope.set_tags(siret: @siret)
|
||||
scope.set_extras(source: data)
|
||||
if data
|
||||
result[:entreprise_capital_social] = data[:capital][:montant] if data[:capital]
|
||||
result[:entreprise_nom_commercial] = data[:nom_commercial]
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
24
app/lib/api_entreprise/tva_adapter.rb
Normal file
24
app/lib/api_entreprise/tva_adapter.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class APIEntreprise::TvaAdapter < APIEntreprise::Adapter
|
||||
# Doc métier : https://entreprise.api.gouv.fr/catalogue/commission_europeenne/numero_tva
|
||||
# Swagger : https://entreprise.api.gouv.fr/developpeurs/openapi#tag/Informations-generales/paths/~1v3~1european_commission~1unites_legales~1%7Bsiren%7D~1numero_tva/get
|
||||
|
||||
private
|
||||
|
||||
def get_resource
|
||||
api(@procedure_id).tva(siren)
|
||||
end
|
||||
|
||||
def process_params
|
||||
Sentry.with_scope do |scope|
|
||||
data = data_source[:data]
|
||||
scope.set_tags(siret: @siret)
|
||||
scope.set_extras(source: data)
|
||||
|
||||
result = {}
|
||||
if data
|
||||
result[:entreprise_numero_tva_intracommunautaire] = data[:tva_number]
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
|
@ -47,7 +47,8 @@ class APIEntrepriseService
|
|||
|
||||
def perform_later_fetch_jobs(etablissement, procedure_id, user_id, wait: nil)
|
||||
[
|
||||
APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
|
||||
APIEntreprise::EntrepriseJob, APIEntreprise::ExtraitKbisJob, APIEntreprise::TvaJob,
|
||||
APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
|
||||
APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob,
|
||||
APIEntreprise::BilansBdfJob
|
||||
].each do |job|
|
||||
|
|
|
@ -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"])
|
||||
|
|
|
@ -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"])
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
228
spec/fixtures/files/api_entreprise/entreprises.json
vendored
228
spec/fixtures/files/api_entreprise/entreprises.json
vendored
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
81
spec/fixtures/files/api_entreprise/extrait_kbis.json
vendored
Normal file
81
spec/fixtures/files/api_entreprise/extrait_kbis.json
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
{
|
||||
"data": {
|
||||
"siren": "130025265",
|
||||
"date_radiation": "2019-01-01",
|
||||
"date_extrait": "2022-07-11",
|
||||
"date_immatriculation": "1998-07-12",
|
||||
"mandataires_sociaux": [
|
||||
{
|
||||
"numero_identification": "784824153",
|
||||
"type": "personne_morale",
|
||||
"fonction": "COMMISSAIRE AUX COMPTES SUPPLEANT",
|
||||
"nom": "Henri",
|
||||
"prenom": "Martin",
|
||||
"date_naissance": "1965-01",
|
||||
"raison_sociale": "BCRH & ASSOCIES - SOCIETE A RESPONSABILITE LIMITEE A ASSOCIE UNIQUE"
|
||||
}
|
||||
],
|
||||
"observations": [
|
||||
{
|
||||
"numero": "123456",
|
||||
"libelle": "LA SOCIETE NE CONSERVE AUCUNE ACTIVITE A SON ANCIEN SIEGE",
|
||||
"date": "2000-01-01"
|
||||
}
|
||||
],
|
||||
"nom_commercial": "DECATHLON",
|
||||
"etablissement_principal": {
|
||||
"activite": "dummy",
|
||||
"origine_fonds": "CREATION",
|
||||
"mode_exploitation": "EXPLOITATION DIRECTE",
|
||||
"code_ape": "6420Z"
|
||||
},
|
||||
"capital": {
|
||||
"montant": 50123.6,
|
||||
"devise": "EUROS",
|
||||
"code_devise": "EUR"
|
||||
},
|
||||
"greffe": {
|
||||
"valeur": "COLMAR",
|
||||
"code": "6851"
|
||||
},
|
||||
"personne_physique": {
|
||||
"adresse": {
|
||||
"nom_postal": "22 RUE DE LA PAIX",
|
||||
"numero": "22",
|
||||
"type": "RUE",
|
||||
"voie": "DE LA PAIX",
|
||||
"ligne_1": "dummy",
|
||||
"ligne_2": "dummy",
|
||||
"localite": "dummy",
|
||||
"code_postal": "75016\"",
|
||||
"bureau_distributeur": "dummy",
|
||||
"pays": "FRANCE"
|
||||
},
|
||||
"nationalite": {
|
||||
"valeur": "FRANÇAISE",
|
||||
"code": "FR"
|
||||
},
|
||||
"nom": "MARTIN",
|
||||
"prenom": "JEAN-MARIE",
|
||||
"naissance": {
|
||||
"pays": {
|
||||
"valeur": "FRANCE",
|
||||
"code": "FR"
|
||||
},
|
||||
"date": "1972-01-30",
|
||||
"lieu": "MONTPELLIER"
|
||||
}
|
||||
},
|
||||
"personne_morale": {
|
||||
"forme_juridique": {
|
||||
"valeur": "SOCIETE PAR ACTIONS SIMPLIFIEES",
|
||||
"code": "SASh"
|
||||
},
|
||||
"denomination": "2X INVEST",
|
||||
"date_cloture_exercice_comptable": "02-24",
|
||||
"date_fin_de_vie": "2075-05-18"
|
||||
}
|
||||
},
|
||||
"links": {},
|
||||
"meta": {}
|
||||
}
|
7
spec/fixtures/files/api_entreprise/tva.json
vendored
Normal file
7
spec/fixtures/files/api_entreprise/tva.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"data": {
|
||||
"tva_number": "FR48672039971"
|
||||
},
|
||||
"links": {},
|
||||
"meta": {}
|
||||
}
|
|
@ -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
|
||||
|
|
22
spec/jobs/api_entreprise/extrait_kbis_job_spec.rb
Normal file
22
spec/jobs/api_entreprise/extrait_kbis_job_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
describe APIEntreprise::ExtraitKbisJob, type: :job do
|
||||
let(:etablissement) { create(:etablissement, siret: siret) }
|
||||
let(:siret) { '13002526500013' }
|
||||
let(:siren) { '130025265' }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/extrait_kbis.json') }
|
||||
let(:status) { 200 }
|
||||
subject { APIEntreprise::ExtraitKbisJob.new.perform(etablissement.id, procedure_id) }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/infogreffe\/rcs\/unites_legales\/#{siren}\/extrait_kbis/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
it 'updates etablissement' do
|
||||
subject
|
||||
expect(Etablissement.find(etablissement.id).entreprise_capital_social).to eq(50123)
|
||||
expect(Etablissement.find(etablissement.id).entreprise_nom_commercial).to eq('DECATHLON')
|
||||
end
|
||||
end
|
21
spec/jobs/api_entreprise/tva_job_spec.rb
Normal file
21
spec/jobs/api_entreprise/tva_job_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
describe APIEntreprise::TvaJob, type: :job do
|
||||
let(:etablissement) { create(:etablissement, siret: siret) }
|
||||
let(:siret) { '41816609600069' }
|
||||
let(:siren) { '418166096' }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/tva.json') }
|
||||
let(:status) { 200 }
|
||||
subject { APIEntreprise::TvaJob.new.perform(etablissement.id, procedure_id) }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/european_commission\/unites_legales\/#{siren}\/numero_tva/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
it 'updates etablissement' do
|
||||
subject
|
||||
expect(Etablissement.find(etablissement.id).entreprise_numero_tva_intracommunautaire).to eq("FR48672039971")
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
29
spec/lib/api_entreprise/extrait_kbis_adapter_spec.rb
Normal file
29
spec/lib/api_entreprise/extrait_kbis_adapter_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
describe APIEntreprise::ExtraitKbisAdapter do
|
||||
let(:siren) { '130025265' }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:adapter) { described_class.new(siren, procedure_id) }
|
||||
subject { adapter.to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/infogreffe\/rcs\/unites_legales\/#{siren}\/extrait_kbis/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
context "when the SIRET is valid" do
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/extrait_kbis.json') }
|
||||
let(:status) { 200 }
|
||||
|
||||
it '#to_params class est une Hash ?' do
|
||||
expect(subject).to be_an_instance_of(Hash)
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un capital_social' do
|
||||
expect(subject[:entreprise_capital_social]).to eq(50123.6)
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un nom_commercial' do
|
||||
expect(subject[:entreprise_nom_commercial]).to eq('DECATHLON')
|
||||
end
|
||||
end
|
||||
end
|
26
spec/lib/api_entreprise/tva_adapter_spec.rb
Normal file
26
spec/lib/api_entreprise/tva_adapter_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
describe APIEntreprise::TvaAdapter do
|
||||
let(:siren) { '418166096' }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:adapter) { described_class.new(siren, procedure_id) }
|
||||
subject { adapter.to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/european_commission\/unites_legales\/#{siren}\/numero_tva/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context "when the SIRET is valid" do
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/tva.json') }
|
||||
let(:status) { 200 }
|
||||
|
||||
it '#to_params class est une Hash ?' do
|
||||
expect(subject).to be_an_instance_of(Hash)
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un numero_tva_intracommunautaire' do
|
||||
expect(subject[:entreprise_numero_tva_intracommunautaire]).to eq("FR48672039971")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
describe APIEntrepriseService do
|
||||
shared_examples 'schedule fetch of all etablissement params' do
|
||||
[
|
||||
APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
|
||||
APIEntreprise::EntrepriseJob, APIEntreprise::ExtraitKbisJob, APIEntreprise::TvaJob,
|
||||
APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
|
||||
APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob,
|
||||
APIEntreprise::BilansBdfJob
|
||||
].each do |job|
|
||||
|
@ -15,12 +16,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 }
|
||||
|
|
|
@ -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'))
|
||||
|
|
|
@ -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\//)
|
||||
|
|
|
@ -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\//)
|
||||
|
|
Loading…
Reference in a new issue