demarches-normaliennes/spec/controllers/address_controller_spec.rb

47 lines
1.6 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe AddressController, type: :controller do
2018-10-15 23:40:39 +02:00
describe '#GET suggestions' do
subject { get :suggestions, params: { request: request } }
before do
2016-12-16 17:51:07 +01:00
subject
end
2018-10-15 16:33:42 +02:00
context 'when request return result', vcr: { cassette_name: 'api_adresse_search_paris_2' } do
2016-12-16 17:51:07 +01:00
let (:request) { 'Paris' }
2016-12-16 17:51:07 +01:00
it { expect(response.status).to eq 200 }
it { expect(response.body).to eq '[{"label":"Paris"},{"label":"Paris 63120 Courpière"},{"label":"PARIS (Vaillac) 46240 Cœur de Causse"},{"label":"Paris 40500 Saint-Sever"},{"label":"Paris Buton 37140 Bourgueil"}]' }
end
2018-10-15 16:33:42 +02:00
context 'when request return nothing', vcr: { cassette_name: 'api_adresse_search_nothing_2' } do
2016-12-16 17:51:07 +01:00
let (:request) { 'je recherche pas grand chose' }
it { expect(response.status).to eq 200 }
it { expect(response.body).to eq "[]" }
end
end
2016-12-16 15:18:34 +01:00
describe '#GET geocode' do
2016-12-16 15:18:34 +01:00
let(:dossier_id) { "1" }
subject { get :geocode, params: { request: request, dossier_id: dossier_id } }
2016-12-16 15:18:34 +01:00
before do
subject
end
2018-10-15 16:33:42 +02:00
context 'when request return result', vcr: { cassette_name: 'api_adresse_search_paris' } do
2016-12-16 15:18:34 +01:00
let(:request) { 'Paris' }
it { expect(response.body).to eq ({ lon: '2.3469', lat: '48.8589', zoom: '14', dossier_id: dossier_id }).to_json }
2016-12-16 15:18:34 +01:00
end
2018-10-15 16:33:42 +02:00
context 'when request return nothing', vcr: { cassette_name: 'api_adresse_search_nothing' } do
2016-12-16 15:18:34 +01:00
let(:request) { 'je recherche pas grand chose' }
it { expect(response.body).to eq ({ lon: nil, lat: nil, zoom: '14', dossier_id: dossier_id }).to_json }
2016-12-16 15:18:34 +01:00
end
end
end