Revert "Merge pull request #4552 from tchak/champ-communes"

This reverts commit 4cec26f73a, reversing
changes made to 0ef25ef36c.
This commit is contained in:
clemkeirua 2020-01-13 16:26:27 +01:00
parent c9ac7294f5
commit 4373cb22cb
63 changed files with 1119 additions and 260 deletions

View file

@ -0,0 +1,44 @@
require 'spec_helper'
describe ApiAdresse::AddressAdapter do
describe '#get_suggestions' do
let(:request) { 'Paris' }
let(:response) { File.open('spec/fixtures/files/api_adresse/search_results.json') }
let(:status) { 200 }
subject { described_class.new(request).get_suggestions }
before do
stub_request(:get, "https://api-adresse.data.gouv.fr/search?&q=#{request}&limit=5")
.to_return(status: status, body: response, headers: {})
end
context 'when address return a list of address' do
it { expect(subject.size).to eq 5 }
it { is_expected.to be_an_instance_of Array }
end
context 'when address return an empty list' do
let(:response) { File.open('spec/fixtures/files/api_adresse/search_no_results.json') }
it { expect(subject.size).to eq 0 }
it { is_expected.to be_an_instance_of Array }
end
context 'when BAN is unavailable' do
let(:status) { 503 }
let(:response) { '' }
it { expect(subject.size).to eq 0 }
it { is_expected.to be_an_instance_of Array }
end
context 'when request is empty' do
let(:response) { 'Missing query' }
let(:request) { '' }
it { expect(subject.size).to eq 0 }
it { is_expected.to be_an_instance_of Array }
end
end
end

View file

@ -0,0 +1,31 @@
require 'spec_helper'
describe ApiAdresse::PointAdapter do
let(:address) { '50 av des champs elysees' }
describe '.geocode', vcr: { cassette_name: 'api_adresse_octo' } do
it 'return a point' do
expect(described_class.new(address).geocode.class).to eq(RGeo::Cartesian::PointImpl)
end
context 'when RestClient::Exception' do
before do
allow(ApiAdresse::API).to receive(:call).and_raise(RestClient::Exception)
end
it 'return nil' do
expect(described_class.new(address).geocode).to be_nil
end
end
context 'when JSON::ParserError' do
before do
allow(JSON).to receive(:parse).and_raise(JSON::ParserError)
end
it 'return nil' do
expect(described_class.new(address).geocode).to be_nil
end
end
end
end

View file

@ -0,0 +1,75 @@
require 'spec_helper'
describe ApiGeo::API do
describe '.regions', vcr: { cassette_name: 'api_geo_regions' } do
subject { described_class.regions }
it { expect(subject.size).to eq 18 }
end
describe '.departements', vcr: { cassette_name: 'api_geo_departements' } do
subject { described_class.departements }
it { expect(subject.size).to eq 101 }
end
describe '.pays' do
subject { described_class.pays }
let(:pays) {
JSON.parse(File.open('app/lib/api_geo/pays.json').read, symbolize_names: true)
}
it { is_expected.to eq pays }
end
describe '.search_rpg', vcr: { cassette_name: 'api_geo_search_rpg' } do
let(:coordinates) do
[
[
2.3945903778076176,
46.53312237252731
],
[
2.394933700561524,
46.532590956418076
],
[
2.3948478698730473,
46.53170525134736
],
[
2.393732070922852,
46.530760483351195
],
[
2.3909854888916016,
46.5309376286023
],
[
2.391414642333985,
46.531232869403546
],
[
2.3913288116455083,
46.53253190986272
],
[
2.39278793334961,
46.53329951007484
],
[
2.3945903778076176,
46.53312237252731
]
]
end
let(:geo_json) {
GeojsonService.to_json_polygon_for_rpg(coordinates)
}
subject { described_class.search_rpg(geo_json) }
it { expect(subject[:features].size).to eq 3 }
end
end

View file

@ -0,0 +1,62 @@
require 'spec_helper'
describe ApiGeo::RPGAdapter do
subject { described_class.new(coordinates).results }
let(:coordinates) do
[
[
2.3945903778076176,
46.53312237252731
],
[
2.394933700561524,
46.532590956418076
],
[
2.3948478698730473,
46.53170525134736
],
[
2.393732070922852,
46.530760483351195
],
[
2.3909854888916016,
46.5309376286023
],
[
2.391414642333985,
46.531232869403546
],
[
2.3913288116455083,
46.53253190986272
],
[
2.39278793334961,
46.53329951007484
],
[
2.3945903778076176,
46.53312237252731
]
]
end
context 'coordinates are filled', vcr: { cassette_name: 'api_geo_search_rpg' } do
describe 'Attribut filter' do
it { expect(subject.size).to eq(3) }
it do
expect(subject.first.keys).to eq([
:culture,
:code_culture,
:surface,
:bio,
:geometry,
:geo_reference_id
])
end
end
end
end