fix(api_geo): include Paris, Lyon and Marseille code INSEE in local data
This commit is contained in:
parent
f0053af54f
commit
378e15e083
3 changed files with 18 additions and 4 deletions
|
@ -70,6 +70,7 @@ class APIGeoService
|
|||
|
||||
def communes_by_postal_code(postal_code)
|
||||
communes_by_postal_code_map.fetch(postal_code, [])
|
||||
.filter { !_1[:code].in?(['75056', '13055', '69123']) }
|
||||
.sort_by { I18n.transliterate([_1[:name], _1[:postal_code]].join(' ')) }
|
||||
end
|
||||
|
||||
|
|
|
@ -24,9 +24,7 @@ namespace :api_geo_data do
|
|||
data = []
|
||||
PATH.join("#{filename}.json").open('w') do |f|
|
||||
response = Typhoeus.get("#{API_GEO_URL}/#{query}")
|
||||
json = JSON.parse(response.body).map(&:symbolize_keys).filter do |result|
|
||||
!result[:code].in?(['75056', '13055', '69123'])
|
||||
end.flat_map do |result|
|
||||
json = JSON.parse(response.body).map(&:symbolize_keys).flat_map do |result|
|
||||
item = {
|
||||
name: result[:nom].tr("'", '’'),
|
||||
code: result[:code],
|
||||
|
@ -42,7 +40,7 @@ namespace :api_geo_data do
|
|||
end
|
||||
end
|
||||
data = json
|
||||
f << JSON.dump(json)
|
||||
f << JSON.pretty_generate(json.sort_by { _1[:code] })
|
||||
end
|
||||
data
|
||||
end
|
||||
|
|
|
@ -59,6 +59,21 @@ describe APIGeoService do
|
|||
describe 'commune_name' do
|
||||
subject { APIGeoService.commune_name('01', '01457') }
|
||||
it { is_expected.to eq('Vonnas') }
|
||||
|
||||
context 'Paris' do
|
||||
subject { APIGeoService.commune_name('75', '75056') }
|
||||
it { is_expected.to eq('Paris') }
|
||||
end
|
||||
|
||||
context 'Lyon' do
|
||||
subject { APIGeoService.commune_name('69', '69123') }
|
||||
it { is_expected.to eq('Lyon') }
|
||||
end
|
||||
|
||||
context 'Marseille' do
|
||||
subject { APIGeoService.commune_name('13', '13055') }
|
||||
it { is_expected.to eq('Marseille') }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'commune_code' do
|
||||
|
|
Loading…
Reference in a new issue