Add tests for Carto Geocodeur
This commit is contained in:
parent
ee82e7fa8a
commit
5b8f0304f9
2 changed files with 73 additions and 0 deletions
47
spec/fixtures/cassettes/bano_octo.yml
vendored
Normal file
47
spec/fixtures/cassettes/bano_octo.yml
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: get
|
||||
uri: http://api-adresse.data.gouv.fr/search?limit=1&q=50%20av%20des%20champs%20elysees
|
||||
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 16:22:23 GMT
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Content-Length:
|
||||
- '628'
|
||||
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": "50 av des champs elysees", "type": "FeatureCollection", "features":
|
||||
[{"geometry": {"type": "Point", "coordinates": [2.306888, 48.870374]}, "properties":
|
||||
{"citycode": "75108", "postcode": "75008", "name": "50 Avenue des Champs \u00c9lys\u00e9es",
|
||||
"id": "ADRNIVX_0000000270748251", "type": "housenumber", "context": "75, \u00cele-de-France",
|
||||
"score": 0.7561038961038961, "label": "50 Avenue des Champs \u00c9lys\u00e9es
|
||||
75008 Paris", "city": "Paris", "housenumber": "50", "street": "Avenue des
|
||||
Champs \u00c9lys\u00e9es"}, "type": "Feature"}]}'
|
||||
http_version:
|
||||
recorded_at: Fri, 16 Dec 2016 16:22:23 GMT
|
||||
recorded_with: VCR 3.0.3
|
26
spec/lib/carto/geocodeur_spec.rb
Normal file
26
spec/lib/carto/geocodeur_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Carto::Geocodeur do
|
||||
let(:address) { '50 av des champs elysees' }
|
||||
describe '.convert_adresse_to_point', vcr: { cassette_name: 'bano_octo' } do
|
||||
it 'return a point' do
|
||||
expect(described_class.convert_adresse_to_point(address).class).to eq(RGeo::Cartesian::PointImpl)
|
||||
end
|
||||
context 'when RestClient::Exception' do
|
||||
before do
|
||||
allow_any_instance_of(Carto::Bano::Driver).to receive(:call).and_raise(RestClient::Exception)
|
||||
end
|
||||
it 'return nil' do
|
||||
expect(described_class.convert_adresse_to_point(address)).to be_nil
|
||||
end
|
||||
end
|
||||
context 'when JSON::ParserError' do
|
||||
before do
|
||||
allow_any_instance_of(Carto::Bano::PointRetriever).to receive(:point).and_raise(JSON::ParserError)
|
||||
end
|
||||
it 'return nil' do
|
||||
expect(described_class.convert_adresse_to_point(address)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue