Merge pull request #10282 from tchak/fix-parse-ban-adresse

fix(adresse): fallback to city name if commune not found
This commit is contained in:
Paul Chavard 2024-04-08 12:58:06 +00:00 committed by GitHub
commit 37ae3142ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -101,7 +101,7 @@ class APIGeoService
department_code:,
region_name: region_name(region_code),
region_code:,
city_name: commune_name(department_code, city_code),
city_name: commune_name(department_code, city_code) || properties['city'], # fallback to city name if commune not found
city_code:
}
else

View file

@ -87,4 +87,24 @@ describe APIGeoService do
expect(APIGeoService.epcis('01').first).to eq(code: '200042935', name: 'CA Haut - Bugey Agglomération')
end
end
describe 'parse_ban_address' do
let(:features) { JSON.parse(Rails.root.join('spec/fixtures/files/api_address/address.json').read)['features'] }
let(:feature) { features.first }
subject { APIGeoService.parse_ban_address(feature) }
context 'with a valid code insee' do
it { expect(subject[:city_name]).to eq('Paris') }
end
context 'with an invalid code insee' do
let(:feature) do
features.first.tap {
_1['properties']['citycode'] = '0000'
}
end
it { expect(subject[:city_name]).to eq('Paris') }
end
end
end