demarches-normaliennes/spec/lib/carto/sgmap/api_spec.rb
Xavier J d48c600476 Add lib API SGMAP Cartography Cadastre
Adapt lib API SGMAP Cartography Quartier Prioritaire at the new API architecture
2016-01-12 17:24:42 +01:00

79 lines
2.2 KiB
Ruby

require 'spec_helper'
describe CARTO::SGMAP::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 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