diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index d348ec530..94160e2b1 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -211,7 +211,12 @@ class Etablissement < ApplicationRecord end def champ_value_json - APIGeoService.parse_etablissement_address(self) + address_data = APIGeoService.parse_etablissement_address(self) + + DISPLAYABLE_COLUMNS.keys.each_with_object(address_data) do |attr, hash| + value = public_send(attr) + hash[attr.to_sym] = value if value.present? + end end private diff --git a/spec/models/etablissement_spec.rb b/spec/models/etablissement_spec.rb index 5cf5cb15a..f46c2a93b 100644 --- a/spec/models/etablissement_spec.rb +++ b/spec/models/etablissement_spec.rb @@ -152,10 +152,18 @@ describe Etablissement do 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 + } - expect(champ.reload.value_json).to eq(address_data) + it 'updates the associated champ value_json with geocoded address' do + expect(value_json).to include(address_data.stringify_keys) + end + + it 'includes jsonpathables columns 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 end diff --git a/spec/tasks/maintenance/populate_siret_value_json_task_spec.rb b/spec/tasks/maintenance/populate_siret_value_json_task_spec.rb index 2bb454fe4..fbc2600b4 100644 --- a/spec/tasks/maintenance/populate_siret_value_json_task_spec.rb +++ b/spec/tasks/maintenance/populate_siret_value_json_task_spec.rb @@ -29,7 +29,14 @@ module Maintenance "departement_code" => "92", "department_code" => "92", "departement_name" => "Hauts-de-Seine", - "department_name" => "Hauts-de-Seine" + "department_name" => "Hauts-de-Seine", + + "entreprise_date_creation" => "1990-04-24", + "entreprise_forme_juridique" => "SA à conseil d'administration (s.a.i.)", + "entreprise_nom_commercial" => "GRTGAZ", + "entreprise_raison_sociale" => "GRTGAZ", + "entreprise_siren" => "440117620", + "libelle_naf" => "Transports par conduites" }) end end