feat(rnf): also store rnf title

This commit is contained in:
mfo 2024-11-15 09:20:40 +01:00
parent 4b740f8f29
commit a9237bf7f1
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
3 changed files with 25 additions and 15 deletions

View file

@ -16,7 +16,7 @@ class Champs::RNFChamp < Champ
end
def update_with_external_data!(data:)
update!(data:, value_json: APIGeoService.parse_rnf_address(data[:address]))
update!(data:, value_json: extract_value_json(data:))
end
def fetch_external_data?
@ -109,4 +109,11 @@ class Champs::RNFChamp < Champ
address['label']
end
end
private
def extract_value_json(data:)
h = APIGeoService.parse_rnf_address(data[:address])
h.merge(title: data[:title])
end
end

View file

@ -102,18 +102,19 @@ describe Champs::RNFChamp, type: :model do
describe 'update_with_external_data!' do
it 'works' do
value_json = {
:street_number => "16",
:street_name => "Rue du Général de Boissieu",
:street_address => "16 Rue du Général de Boissieu",
:postal_code => "75015",
:city_name => "Paris 15e Arrondissement",
:city_code => "75115",
:departement_code => "75",
:department_code => "75",
:departement_name => "Paris",
:department_name => "Paris",
:region_code => "11",
:region_name => "Île-de-France"
street_number: "16",
street_name: "Rue du Général de Boissieu",
street_address: "16 Rue du Général de Boissieu",
postal_code: "75015",
city_name: "Paris 15e Arrondissement",
city_code: "75115",
departement_code: "75",
department_code: "75",
departement_name: "Paris",
department_name: "Paris",
region_code: "11",
region_name: "Île-de-France",
title: "Fondation SFR"
}
expect(champ).to receive(:update!).with(data: anything, value_json:)
champ.update_with_external_data!(data: subject.value!)

View file

@ -66,7 +66,8 @@ module Maintenance
"departement_name" => "Paris",
"department_name" => "Paris",
"region_code" => "11",
"region_name" => "Île-de-France"
"region_name" => "Île-de-France",
"title" => "Fondation SFR"
})
end
end
@ -92,7 +93,8 @@ module Maintenance
"departement_name" => "Paris",
"department_name" => "Paris",
"region_code" => "11",
"region_name" => "Île-de-France"
"region_name" => "Île-de-France",
"title" => "Fondation SFR"
})
end
end