chore(entreprises): save etat_administratif from API
This commit is contained in:
parent
e1d3d1f844
commit
f05e9331a7
5 changed files with 28 additions and 1 deletions
|
@ -7,6 +7,7 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
|
|||
|
||||
def process_params
|
||||
params = data_source[:entreprise]&.slice(*attr_to_fetch)
|
||||
params[:etat_administratif] = map_etat_administratif(data_source)
|
||||
|
||||
if params.present? && valid_params?(params)
|
||||
params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime
|
||||
|
@ -32,4 +33,13 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
|
|||
:prenom
|
||||
]
|
||||
end
|
||||
|
||||
def map_etat_administratif(data_source)
|
||||
raw_value = data_source.dig(:entreprise, :etat_administratif, :value) # data structure will change in v3
|
||||
|
||||
case raw_value
|
||||
when 'A' then 'actif'
|
||||
when 'F' then 'fermé'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,7 @@ class Entreprise < Hashie::Dash
|
|||
property :raison_sociale
|
||||
property :siret_siege_social
|
||||
property :code_effectif_entreprise
|
||||
property :etat_administratif
|
||||
property :effectif_mois
|
||||
property :effectif_annee
|
||||
property :effectif_mensuel
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
"date_reference": "2014",
|
||||
"intitule": "200 à 249 salariés"
|
||||
},
|
||||
"etat_administratif": {
|
||||
"value": "A",
|
||||
"date_cessation": null
|
||||
},
|
||||
"exercices": [
|
||||
{
|
||||
"chiffre_affaires": null,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
RSpec.describe APIEntreprise::EntrepriseJob, type: :job do
|
||||
let(:siret) { '41816609600051' }
|
||||
let(:siren) { '418166096' }
|
||||
let(:etablissement) { create(:etablissement, siret: siret) }
|
||||
let(:etablissement) { create(:etablissement, siret: siret, entreprise_etat_administratif: nil) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') }
|
||||
|
@ -19,4 +19,12 @@ RSpec.describe APIEntreprise::EntrepriseJob, type: :job do
|
|||
subject
|
||||
expect(Etablissement.find(etablissement.id).entreprise_numero_tva_intracommunautaire).to eq('FR16418166096')
|
||||
end
|
||||
|
||||
it 'convert entreprise etat_administratif source to an enum' do
|
||||
subject
|
||||
etablissement.reload
|
||||
|
||||
expect(etablissement.entreprise_etat_administratif).to eq("actif")
|
||||
expect(etablissement.entreprise_etat_administratif_actif?)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,6 +67,10 @@ describe APIEntreprise::EntrepriseAdapter do
|
|||
it 'L\'entreprise contient bien un prenom' do
|
||||
expect(subject[:entreprise_prenom]).to eq('test_prenom')
|
||||
end
|
||||
|
||||
it 'L\'entreprise contient bien un etat administratif' do
|
||||
expect(subject[:entreprise_etat_administratif]).to eq('actif')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue