2016-01-12 17:24:42 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe CARTO::SGMAP::Cadastre::Adapter do
|
|
|
|
subject { described_class.new(coordinates).to_params }
|
|
|
|
|
|
|
|
before do
|
2017-06-12 15:16:15 +02:00
|
|
|
stub_request(:post, "https://apicarto.sgmap.fr/cadastre/geometrie")
|
2018-01-15 19:34:08 +01:00
|
|
|
.with(:body => /.*/,
|
2018-01-16 13:34:24 +01:00
|
|
|
:headers => { 'Content-Type' => 'application/json' })
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(status: status, body: body)
|
2016-01-12 17:24:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'coordinates are filled' do
|
|
|
|
let(:coordinates) { '[[2.252728, 43.27151][2.323223, 32.835332]]' }
|
|
|
|
let(:status) { 200 }
|
|
|
|
let(:body) { File.read('spec/support/files/geojson/response_cadastre.json') }
|
|
|
|
|
|
|
|
it { expect(subject).to be_a_instance_of(Array) }
|
2018-10-15 15:48:01 +02:00
|
|
|
it { expect(subject.size).to eq(16) }
|
2016-01-12 17:24:42 +01:00
|
|
|
|
2016-01-18 12:03:18 +01:00
|
|
|
describe 'Attribut filter' do
|
|
|
|
let(:adapter) { described_class.new(coordinates) }
|
2018-10-15 16:12:51 +02:00
|
|
|
subject { adapter.filter_properties(adapter.data_source[:features].first[:properties]) }
|
2016-01-18 12:03:18 +01:00
|
|
|
|
2018-10-15 15:48:01 +02:00
|
|
|
it { expect(subject.size).to eq(9) }
|
2018-01-15 18:54:57 +01:00
|
|
|
it do
|
2018-10-15 15:48:01 +02:00
|
|
|
expect(subject.keys).to eq([
|
2018-01-15 19:12:15 +01:00
|
|
|
:surface_intersection,
|
|
|
|
:surface_parcelle,
|
|
|
|
:numero,
|
|
|
|
:feuille,
|
|
|
|
:section,
|
|
|
|
:code_dep,
|
|
|
|
:nom_com,
|
|
|
|
:code_com,
|
|
|
|
:code_arr
|
2018-10-15 15:48:01 +02:00
|
|
|
])
|
2018-01-15 18:54:57 +01:00
|
|
|
end
|
2016-01-18 12:03:18 +01:00
|
|
|
end
|
|
|
|
|
2016-01-12 17:24:42 +01:00
|
|
|
describe 'Attributes' do
|
|
|
|
subject { super().first }
|
|
|
|
|
|
|
|
it { expect(subject[:surface_intersection]).to eq('0.0202') }
|
|
|
|
it { expect(subject[:surface_parcelle]).to eq(220.0664659755941) }
|
|
|
|
it { expect(subject[:numero]).to eq('0082') }
|
|
|
|
it { expect(subject[:feuille]).to eq(1) }
|
|
|
|
it { expect(subject[:section]).to eq('0J') }
|
|
|
|
it { expect(subject[:code_dep]).to eq('94') }
|
|
|
|
it { expect(subject[:nom_com]).to eq('Maisons-Alfort') }
|
|
|
|
it { expect(subject[:code_com]).to eq('046') }
|
|
|
|
it { expect(subject[:code_arr]).to eq('000') }
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
it { expect(subject[:geometry]).to eq({ type: "MultiPolygon", coordinates: [[[[2.4362443, 48.8092078], [2.436384, 48.8092043], [2.4363802, 48.8091414]]]] }) }
|
2016-01-12 17:24:42 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'coordinates are empty' do
|
|
|
|
let(:coordinates) { '' }
|
|
|
|
let(:status) { 404 }
|
|
|
|
let(:body) { '' }
|
|
|
|
|
|
|
|
it { expect { subject }.to raise_error(RestClient::ResourceNotFound) }
|
|
|
|
end
|
|
|
|
end
|