use api entreprise v3 for effectifs annuels
This commit is contained in:
parent
e5d0d7dda2
commit
0f1e243b01
5 changed files with 46 additions and 18 deletions
|
@ -5,8 +5,8 @@ class APIEntreprise::API
|
|||
TVA_NAME = "v3/european_commission/unites_legales/%{id}/numero_tva"
|
||||
EXERCICES_RESOURCE_NAME = "v3/dgfip/etablissements/%{id}/chiffres_affaires"
|
||||
RNA_RESOURCE_NAME = "v4/djepva/api-association/associations/open_data/%{id}"
|
||||
EFFECTIFS_ANNUELS_RESOURCE_NAME = "v2/effectifs_annuels_acoss_covid/%{id}"
|
||||
EFFECTIFS_RESOURCE_NAME = "v3/gip_mds/etablissements/%{id}/effectifs_mensuels"
|
||||
EFFECTIFS_ANNUELS_RESOURCE_NAME = "v3/gip_mds/unites_legales/%{id}/effectifs_annuels"
|
||||
ATTESTATION_SOCIALE_RESOURCE_NAME = "v4/urssaf/unites_legales/%{id}/attestation_vigilance"
|
||||
ATTESTATION_FISCALE_RESOURCE_NAME = "v4/dgfip/unites_legales/%{id}/attestation_fiscale"
|
||||
BILANS_BDF_RESOURCE_NAME = "v3/banque_de_france/unites_legales/%{id}/bilans"
|
||||
|
@ -55,8 +55,9 @@ class APIEntreprise::API
|
|||
call_with_siret(endpoint, siret)
|
||||
end
|
||||
|
||||
def effectifs_annuels(siren)
|
||||
call_with_siret(EFFECTIFS_ANNUELS_RESOURCE_NAME, siren)
|
||||
def effectifs_annuels(siren, annee)
|
||||
endpoint = [EFFECTIFS_ANNUELS_RESOURCE_NAME, annee].join('/')
|
||||
call_with_siret(endpoint, siren)
|
||||
end
|
||||
|
||||
def attestation_sociale(siren)
|
||||
|
|
|
@ -1,23 +1,34 @@
|
|||
class APIEntreprise::EffectifsAnnuelsAdapter < APIEntreprise::Adapter
|
||||
def initialize(siret, procedure_id)
|
||||
def initialize(siret, procedure_id, year = default_year)
|
||||
@siret = siret
|
||||
@procedure_id = procedure_id
|
||||
@year = year
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_year
|
||||
Date.current.year - 1
|
||||
end
|
||||
|
||||
def get_resource
|
||||
api(@procedure_id).effectifs_annuels(siren)
|
||||
api(@procedure_id).effectifs_annuels(siren, @year)
|
||||
end
|
||||
|
||||
def process_params
|
||||
if data_source[:effectifs_annuels].present?
|
||||
data = data_source.fetch(:data, nil)
|
||||
Sentry.with_scope do |scope|
|
||||
scope.set_tags(siret: @siret)
|
||||
scope.set_extras(source: data)
|
||||
effectifs = data&.fetch(:effectifs_annuel, nil)&.first
|
||||
if effectifs.present?
|
||||
{
|
||||
entreprise_effectif_annuel: data_source[:effectifs_annuels],
|
||||
entreprise_effectif_annuel_annee: data_source[:annee]
|
||||
entreprise_effectif_annuel: effectifs[:value],
|
||||
entreprise_effectif_annuel_annee: effectifs[:annee]
|
||||
}
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
{
|
||||
"data": {
|
||||
"siren": "418166096",
|
||||
"annee": "2019",
|
||||
"effectifs_annuels": 100.5
|
||||
"annee": "2017",
|
||||
"effectifs_annuel": [
|
||||
{
|
||||
"regime": "regime_general",
|
||||
"value": 100.5,
|
||||
"nature": "effectif_moyen_annuel",
|
||||
"date_derniere_mise_a_jour": "2018-01-01"
|
||||
}
|
||||
]
|
||||
},
|
||||
"links": {},
|
||||
"meta": {}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,21 @@ RSpec.describe APIEntreprise::EffectifsAnnuelsJob, type: :job do
|
|||
let(:etablissement) { create(:etablissement, siret: siret) }
|
||||
let(:siret) { '41816609600069' }
|
||||
let(:siren) { '418166096' }
|
||||
let(:now) { Date.parse("2021/02/13") }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/effectifs_annuels.json') }
|
||||
let(:status) { 200 }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/)
|
||||
Timecop.freeze(now)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/gip_mds\/unites_legales\/#{siren}\/effectifs_annuels\/2020/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
||||
subject { APIEntreprise::EffectifsAnnuelsJob.new.perform(etablissement.id, procedure_id) }
|
||||
|
||||
it 'updates etablissement' do
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
describe APIEntreprise::EffectifsAnnuelsAdapter do
|
||||
let(:siret) { '41816609600069' }
|
||||
let(:siren) { '418166096' }
|
||||
let(:annee) { 2017 }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:adapter) { described_class.new(siret, procedure_id) }
|
||||
let(:adapter) { described_class.new(siret, procedure_id, annee) }
|
||||
subject { adapter.to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/gip_mds\/unites_legales\/#{siren}\/effectifs_annuels\/#{annee}/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue