2016-01-12 17:24:42 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe CARTO::SGMAP::API do
|
|
|
|
describe '.search_qp' do
|
|
|
|
subject { described_class.search_qp(geojson) }
|
|
|
|
|
|
|
|
before do
|
2017-06-12 15:16:15 +02:00
|
|
|
stub_request(:post, "https://apicarto.sgmap.fr/quartiers-prioritaires/search")
|
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 '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
|
|
|
|
|
2016-12-20 12:27:53 +01:00
|
|
|
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
|
|
|
|
|
2016-01-12 17:24:42 +01:00
|
|
|
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
|
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 '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
|