CARTO::SGMAP → ApiCarto
This commit is contained in:
parent
442b4a241b
commit
d726fbf698
8 changed files with 13 additions and 13 deletions
89
spec/lib/api_carto/api_spec.rb
Normal file
89
spec/lib/api_carto/api_spec.rb
Normal file
|
@ -0,0 +1,89 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ApiCarto::API do
|
||||
describe '.search_qp' do
|
||||
subject { described_class.search_qp(geojson) }
|
||||
|
||||
before do
|
||||
stub_request(:post, "https://apicarto.sgmap.fr/quartiers-prioritaires/search")
|
||||
.with(:body => /.*/,
|
||||
:headers => { 'Content-Type' => 'application/json' })
|
||||
.to_return(status: status, body: body)
|
||||
end
|
||||
context 'when geojson is empty' do
|
||||
let(:geojson) { '' }
|
||||
let(:status) { 404 }
|
||||
let(:body) { '' }
|
||||
|
||||
it 'raises RestClient::ResourceNotFound' do
|
||||
expect { subject }.to raise_error(RestClient::ResourceNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when request return 500' do
|
||||
let(:geojson) { File.read('spec/support/files/geojson/request_qp.json') }
|
||||
let(:status) { 500 }
|
||||
let(:body) { 'toto' }
|
||||
|
||||
it 'raises RestClient::ResourceNotFound' do
|
||||
expect { subject }.to raise_error(RestClient::ResourceNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when geojson exist' do
|
||||
let(:geojson) { File.read('spec/support/files/geojson/request_qp.json') }
|
||||
let(:status) { 200 }
|
||||
let(:body) { 'toto' }
|
||||
|
||||
it 'returns response body' do
|
||||
expect(subject).to eq(body)
|
||||
end
|
||||
|
||||
context 'when geojson is at format JSON' do
|
||||
let(:geojson) { JSON.parse(File.read('spec/support/files/geojson/request_qp.json')) }
|
||||
|
||||
it 'returns response body' do
|
||||
expect(subject).to eq(body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.search_cadastre' do
|
||||
subject { described_class.search_cadastre(geojson) }
|
||||
|
||||
before do
|
||||
stub_request(:post, "https://apicarto.sgmap.fr/cadastre/geometrie")
|
||||
.with(:body => /.*/,
|
||||
:headers => { 'Content-Type' => 'application/json' })
|
||||
.to_return(status: status, body: body)
|
||||
end
|
||||
context 'when geojson is empty' do
|
||||
let(:geojson) { '' }
|
||||
let(:status) { 404 }
|
||||
let(:body) { '' }
|
||||
|
||||
it 'raises RestClient::ResourceNotFound' do
|
||||
expect { subject }.to raise_error(RestClient::ResourceNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when geojson exist' do
|
||||
let(:geojson) { File.read('spec/support/files/geojson/request_cadastre.json') }
|
||||
let(:status) { 200 }
|
||||
let(:body) { 'toto' }
|
||||
|
||||
it 'returns response body' do
|
||||
expect(subject).to eq(body)
|
||||
end
|
||||
|
||||
context 'when geojson is at format JSON' do
|
||||
let(:geojson) { JSON.parse(File.read('spec/support/files/geojson/request_cadastre.json')) }
|
||||
|
||||
it 'returns response body' do
|
||||
expect(subject).to eq(body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
65
spec/lib/api_carto/cadastre/adapter_spec.rb
Normal file
65
spec/lib/api_carto/cadastre/adapter_spec.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ApiCarto::Cadastre::Adapter do
|
||||
subject { described_class.new(coordinates).results }
|
||||
|
||||
before do
|
||||
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) }
|
||||
it { expect(subject.size).to eq(16) }
|
||||
|
||||
describe 'Attribut filter' do
|
||||
let(:adapter) { described_class.new(coordinates) }
|
||||
subject { adapter.filter_properties(adapter.data_source[:features].first[:properties]) }
|
||||
|
||||
it { expect(subject.size).to eq(9) }
|
||||
it do
|
||||
expect(subject.keys).to eq([
|
||||
:surface_intersection,
|
||||
:surface_parcelle,
|
||||
:numero,
|
||||
:feuille,
|
||||
:section,
|
||||
:code_dep,
|
||||
:nom_com,
|
||||
:code_com,
|
||||
:code_arr
|
||||
])
|
||||
end
|
||||
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
|
38
spec/lib/api_carto/quartiers_prioritaires/adapter_spec.rb
Normal file
38
spec/lib/api_carto/quartiers_prioritaires/adapter_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ApiCarto::QuartiersPrioritaires::Adapter do
|
||||
subject { described_class.new(coordinates).results }
|
||||
|
||||
before do
|
||||
stub_request(:post, "https://apicarto.sgmap.fr/quartiers-prioritaires/search")
|
||||
.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_qp.json') }
|
||||
|
||||
it { expect(subject).to be_a_instance_of(Array) }
|
||||
|
||||
context 'Attributes' do
|
||||
let(:qp_code) { 'QP057019' }
|
||||
|
||||
it { expect(subject.first[:code]).to eq(qp_code) }
|
||||
it { expect(subject.first[:nom]).to eq('Hauts De Vallières') }
|
||||
it { expect(subject.first[:commune]).to eq('Metz') }
|
||||
|
||||
it { expect(subject.first[:geometry]).to eq({ :type => "MultiPolygon", :coordinates => [[[[6.2136923480551, 49.1342109827851], [6.21416055031881, 49.1338823553928]]]] }) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'coordinates are empty' do
|
||||
let(:coordinates) { '' }
|
||||
let(:status) { 404 }
|
||||
let(:body) { '' }
|
||||
|
||||
it { expect { subject }.to raise_error(RestClient::ResourceNotFound) }
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue