2016-01-12 17:24:42 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-10-15 16:54:38 +02:00
|
|
|
describe ApiCarto::API do
|
2016-01-12 17:24:42 +01:00
|
|
|
describe '.search_qp' do
|
|
|
|
subject { described_class.search_qp(geojson) }
|
|
|
|
|
|
|
|
before do
|
2019-07-23 15:37:23 +02:00
|
|
|
stub_request(:post, "https://sandbox.geo.api.gouv.fr/apicarto/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) { '' }
|
|
|
|
|
2020-03-05 13:50:38 +01:00
|
|
|
it 'raises ApiCarto::API::ResourceNotFound' do
|
|
|
|
expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound)
|
2016-01-12 17:24:42 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-20 12:27:53 +01:00
|
|
|
context 'when request return 500' do
|
2018-10-16 00:01:53 +02:00
|
|
|
let(:geojson) { File.read('spec/fixtures/files/api_carto/request_qp.json') }
|
2016-12-20 12:27:53 +01:00
|
|
|
let(:status) { 500 }
|
|
|
|
let(:body) { 'toto' }
|
|
|
|
|
2020-03-05 13:50:38 +01:00
|
|
|
it 'raises ApiCarto::API::ResourceNotFound' do
|
|
|
|
expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound)
|
2016-12-20 12:27:53 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-12 17:24:42 +01:00
|
|
|
context 'when geojson exist' do
|
2018-10-16 00:01:53 +02:00
|
|
|
let(:geojson) { File.read('spec/fixtures/files/api_carto/request_qp.json') }
|
2016-01-12 17:24:42 +01:00
|
|
|
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
|
2018-10-16 00:01:53 +02:00
|
|
|
let(:geojson) { JSON.parse(File.read('spec/fixtures/files/api_carto/request_qp.json')) }
|
2016-01-12 17:24:42 +01:00
|
|
|
|
|
|
|
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
|
2019-07-23 15:37:23 +02:00
|
|
|
stub_request(:post, "https://sandbox.geo.api.gouv.fr/apicarto/cadastre/geometrie")
|
2018-01-15 19:34:08 +01:00
|
|
|
.with(:body => /.*/,
|
2018-09-20 14:34:49 +02: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) { '' }
|
|
|
|
|
2020-03-05 13:50:38 +01:00
|
|
|
it 'raises ApiCarto::API::ResourceNotFound' do
|
|
|
|
expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound)
|
2016-01-12 17:24:42 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when geojson exist' do
|
2018-10-16 00:01:53 +02:00
|
|
|
let(:geojson) { File.read('spec/fixtures/files/api_carto/request_cadastre.json') }
|
2016-01-12 17:24:42 +01:00
|
|
|
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
|
2018-10-16 00:01:53 +02:00
|
|
|
let(:geojson) { JSON.parse(File.read('spec/fixtures/files/api_carto/request_cadastre.json')) }
|
2016-01-12 17:24:42 +01:00
|
|
|
|
|
|
|
it 'returns response body' do
|
|
|
|
expect(subject).to eq(body)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|