demarches-normaliennes/spec/controllers/address_controller_spec.rb
clemkeirua 4373cb22cb Revert "Merge pull request #4552 from tchak/champ-communes"
This reverts commit 4cec26f73a, reversing
changes made to 0ef25ef36c.
2020-01-13 16:26:27 +01:00

46 lines
1.6 KiB
Ruby

require 'spec_helper'
describe AddressController, type: :controller do
describe '#GET suggestions' do
subject { get :suggestions, params: { request: request } }
before do
subject
end
context 'when request return result', vcr: { cassette_name: 'api_adresse_search_paris_2' } do
let (:request) { 'Paris' }
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
context 'when request return nothing', vcr: { cassette_name: 'api_adresse_search_nothing_2' } do
let (:request) { 'je recherche pas grand chose' }
it { expect(response.status).to eq 200 }
it { expect(response.body).to eq "[]" }
end
end
describe '#GET geocode' do
let(:dossier_id) { "1" }
subject { get :geocode, params: { request: request, dossier_id: dossier_id } }
before do
subject
end
context 'when request return result', vcr: { cassette_name: 'api_adresse_search_paris' } do
let(:request) { 'Paris' }
it { expect(response.body).to eq ({ lon: '2.3469', lat: '48.8589', zoom: '14', dossier_id: dossier_id }).to_json }
end
context 'when request return nothing', vcr: { cassette_name: 'api_adresse_search_nothing' } do
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 }
end
end
end