2016-06-09 12:08:18 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-10-15 17:43:08 +02:00
|
|
|
describe ApiAdresse::AddressAdapter do
|
2018-10-15 21:53:52 +02:00
|
|
|
describe '#get_suggestions' do
|
2016-06-09 12:08:18 +02:00
|
|
|
let(:request) { 'Paris' }
|
2018-10-16 00:01:53 +02:00
|
|
|
let(:response) { File.open('spec/fixtures/files/api_adresse/search_results.json') }
|
2016-06-09 12:08:18 +02:00
|
|
|
let(:status) { 200 }
|
|
|
|
|
2018-10-15 21:53:52 +02:00
|
|
|
subject { described_class.new(request).get_suggestions }
|
2016-06-09 12:08:18 +02:00
|
|
|
|
|
|
|
before do
|
2018-10-15 16:36:34 +02:00
|
|
|
stub_request(:get, "https://api-adresse.data.gouv.fr/search?&q=#{request}&limit=5")
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(status: status, body: response, headers: {})
|
2016-06-09 12:08:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when address return a list of address' do
|
|
|
|
it { expect(subject.size).to eq 5 }
|
|
|
|
it { is_expected.to be_an_instance_of Array }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when address return an empty list' do
|
2018-10-16 00:01:53 +02:00
|
|
|
let(:response) { File.open('spec/fixtures/files/api_adresse/search_no_results.json') }
|
2016-06-09 12:08:18 +02:00
|
|
|
|
|
|
|
it { expect(subject.size).to eq 0 }
|
|
|
|
it { is_expected.to be_an_instance_of Array }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when BAN is unavailable' do
|
|
|
|
let(:status) { 503 }
|
|
|
|
let(:response) { '' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq 0 }
|
|
|
|
it { is_expected.to be_an_instance_of Array }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when request is empty' do
|
|
|
|
let(:response) { 'Missing query' }
|
|
|
|
let(:request) { '' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq 0 }
|
|
|
|
it { is_expected.to be_an_instance_of Array }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|