Add tests for SearchController

This commit is contained in:
Xavier J 2016-12-16 15:18:34 +01:00
parent 33bfe4a29c
commit 7c20d1e9a0
3 changed files with 109 additions and 1 deletions

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe Ban::SearchController, type: :controller do
describe '#GET' do
describe '#GET get' do
let (:request) { '' }
before do
@ -13,4 +13,25 @@ describe Ban::SearchController, type: :controller do
it { expect(response.status).to eq 200 }
end
describe '#GET get_address_point' do
let(:dossier_id) { "1" }
subject { get :get_address_point, params: {request: request, dossier_id: dossier_id} }
before do
subject
end
context 'when request return result', vcr: {cassette_name: 'ban_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: 'ban_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

View file

@ -0,0 +1,42 @@
---
http_interactions:
- request:
method: get
uri: http://api-adresse.data.gouv.fr/search?limit=1&q=je%20recherche%20pas%20grand%20chose
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*"
Accept-Encoding:
- gzip, deflate
User-Agent:
- rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112
response:
status:
code: 200
message: OK
headers:
Server:
- nginx/1.11.3
Date:
- Fri, 16 Dec 2016 14:17:40 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '163'
Connection:
- keep-alive
Access-Control-Allow-Origin:
- "*"
Access-Control-Allow-Headers:
- X-Requested-With
body:
encoding: UTF-8
string: '{"limit": 1, "attribution": "BAN", "version": "draft", "licence": "ODbL
1.0", "query": "je recherche pas grand chose", "type": "FeatureCollection",
"features": []}'
http_version:
recorded_at: Fri, 16 Dec 2016 14:17:40 GMT
recorded_with: VCR 3.0.3

View file

@ -0,0 +1,45 @@
---
http_interactions:
- request:
method: get
uri: http://api-adresse.data.gouv.fr/search?limit=1&q=Paris
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*"
Accept-Encoding:
- gzip, deflate
User-Agent:
- rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112
response:
status:
code: 200
message: OK
headers:
Server:
- nginx/1.11.3
Date:
- Fri, 16 Dec 2016 14:16:43 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '457'
Connection:
- keep-alive
Access-Control-Allow-Origin:
- "*"
Access-Control-Allow-Headers:
- X-Requested-With
body:
encoding: UTF-8
string: '{"limit": 1, "attribution": "BAN", "version": "draft", "licence": "ODbL
1.0", "query": "Paris", "type": "FeatureCollection", "features": [{"geometry":
{"type": "Point", "coordinates": [2.3469, 48.8589]}, "properties": {"adm_weight":
"6", "citycode": "75056", "name": "Paris", "city": "Paris", "postcode": "75000",
"context": "75, \u00cele-de-France", "score": 1.0, "label": "Paris", "id":
"75056", "type": "city", "population": "2244"}, "type": "Feature"}]}'
http_version:
recorded_at: Fri, 16 Dec 2016 14:16:43 GMT
recorded_with: VCR 3.0.3