demarches-normaliennes/spec/lib/api_carto/cadastre/adapter_spec.rb

66 lines
2.1 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2018-10-15 16:54:38 +02:00
describe ApiCarto::Cadastre::Adapter do
2018-10-15 16:25:16 +02:00
subject { described_class.new(coordinates).results }
before do
2017-06-12 15:16:15 +02:00
stub_request(:post, "https://apicarto.sgmap.fr/cadastre/geometrie")
.with(:body => /.*/,
:headers => { 'Content-Type' => 'application/json' })
.to_return(status: status, body: body)
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-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([
: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
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') }
it { expect(subject[:geometry]).to eq({ type: "MultiPolygon", coordinates: [[[[2.4362443, 48.8092078], [2.436384, 48.8092043], [2.4363802, 48.8091414]]]] }) }
end
end
context 'coordinates are empty' do
let(:coordinates) { '' }
let(:status) { 404 }
let(:body) { '' }
it { expect { subject }.to raise_error(RestClient::ResourceNotFound) }
end
end