Skip to content

Commit

Permalink
feat(etablissement): save value json data for columns
Browse files Browse the repository at this point in the history
  • Loading branch information
colinux committed Nov 26, 2024
1 parent e45551f commit f6fd8bc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
30 changes: 29 additions & 1 deletion app/models/etablissement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,35 @@ def update_champ_value_json!
end

def champ_value_json
APIGeoService.parse_etablissement_address(self)
attributes = %w[
entreprise_forme_juridique
entreprise_siren
entreprise_nom_commercial
entreprise_raison_sociale
entreprise_siret_siege_social
entreprise_date_creation
libelle_naf
siege_social
naf
entreprise_capital_social
entreprise_numero_tva_intracommunautaire
entreprise_forme_juridique_code
entreprise_code_effectif_entreprise
entreprise_etat_administratif
entreprise_nom
entreprise_prenom
association_rna
association_titre
association_objet
association_date_creation
association_date_declaration
association_date_publication
]

attributes.each_with_object({}) do |attr, hash|
value = public_send(attr)
hash[attr.to_sym] = value if value.present?
end.merge(APIGeoService.parse_etablissement_address(self))
end

private
Expand Down
24 changes: 22 additions & 2 deletions spec/models/etablissement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,30 @@
etablissement.champ = champ
end

it 'updates the associated champ value_json with geocoded address' do
subject(:value_json) {
etablissement.update_champ_value_json!
champ.reload.value_json
}

it 'updates the associated champ value_json with geocoded address' do
expect(value_json).to include(address_data.stringify_keys)
end

expect(champ.reload.value_json).to eq(address_data)
it 'includes non-nil entreprise attributes' do
expect(value_json["entreprise_siren"]).to eq(etablissement.siren)
expect(value_json["entreprise_raison_sociale"]).to eq(etablissement.entreprise_raison_sociale)
end

it 'excludes nil values' do
expect(value_json.keys).not_to include("association_rna")
end

context 'es association attributes' do
let(:etablissement) { create(:etablissement, :is_association) }

it 'includes association attributes' do
expect(value_json["association_rna"]).to eq(etablissement.association_rna)
end
end
end

Expand Down

0 comments on commit f6fd8bc

Please sign in to comment.