From d7416b2d0c028cd2a3bd9c50482e7ef291a7081b Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 2 Feb 2017 16:00:45 -0500 Subject: [PATCH] Fix nominatim / geocoder test (closes #3767) --- test/spec/services/nominatim.js | 47 +++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/test/spec/services/nominatim.js b/test/spec/services/nominatim.js index df3a098e9..554479834 100644 --- a/test/spec/services/nominatim.js +++ b/test/spec/services/nominatim.js @@ -15,88 +15,107 @@ describe('iD.serviceNominatim', function() { return iD.utilStringQs(url.substring(url.indexOf('?') + 1)); } - describe.skip('#countryCode', function() { + + describe('#countryCode', function() { it('calls the given callback with the results of the country code query', function() { var callback = sinon.spy(); nominatim.countryCode([16, 48], callback); - server.respondWith('GET', 'https://nominatim.openstreetmap.org/reverse?addressdetails=1&format=json&lat=48&lon=16', + server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), [200, { 'Content-Type': 'application/json' }, '{"address":{"country_code":"at"}}']); server.respond(); expect(query(server.requests[0].url)).to.eql( {format: 'json', addressdetails: '1', lat: '48', lon: '16'}); - expect(callback).to.have.been.calledWith(null, 'at'); + expect(callback).to.have.been.calledWithExactly(null, 'at'); }); it('should not cache the first country code result', function() { var callback = sinon.spy(); nominatim.countryCode([16, 48], callback); - server.respondWith('GET', 'https://nominatim.openstreetmap.org/reverse?addressdetails=1&format=json&lat=48&lon=16', + server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), [200, { 'Content-Type': 'application/json' }, '{"address":{"country_code":"at"}}']); server.respond(); expect(query(server.requests[0].url)).to.eql( {format: 'json', addressdetails: '1', lat: '48', lon: '16'}); - expect(callback).to.have.been.calledWith(null, 'at'); + expect(callback).to.have.been.calledWithExactly(null, 'at'); server.restore(); server = sinon.fakeServer.create(); nominatim.countryCode([17, 49], callback); - server.respondWith('GET', 'https://nominatim.openstreetmap.org/reverse?addressdetails=1&format=json&lat=49&lon=17', + server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), [200, { 'Content-Type': 'application/json' }, '{"address":{"country_code":"cz"}}']); server.respond(); expect(query(server.requests[0].url)).to.eql( {format: 'json', addressdetails: '1', lat: '49', lon: '17'}); - expect(callback).to.have.been.calledWith(null, 'cz'); + expect(callback).to.have.been.calledWithExactly(null, 'cz'); }); it('should cache the first country code result', function() { var callback = sinon.spy(); nominatim.countryCode([16, 48], callback); - server.respondWith('GET', 'https://nominatim.openstreetmap.org/reverse?addressdetails=1&format=json&lat=48&lon=16', + server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), [200, { 'Content-Type': 'application/json' }, '{"address":{"country_code":"at"}}']); server.respond(); expect(query(server.requests[0].url)).to.eql( {format: 'json', addressdetails: '1', lat: '48', lon: '16'}); - expect(callback).to.have.been.calledWith(null, 'at'); + expect(callback).to.have.been.calledWithExactly(null, 'at'); server.restore(); server = sinon.fakeServer.create(); nominatim.countryCode([16.01, 48.01], callback); - server.respondWith('GET', 'https://nominatim.openstreetmap.org/reverse?addressdetails=1&format=json&lat=48.01&lon=16.01', + server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), [200, { 'Content-Type': 'application/json' }, '{"address":{"country_code":"cz"}}']); server.respond(); - - expect(callback).to.have.been.calledWith(null, 'at'); + expect(callback).to.have.been.calledWithExactly(null, 'at'); }); it('calls the given callback with an error', function() { var callback = sinon.spy(); nominatim.countryCode([1000, 1000], callback); - server.respondWith('GET', 'https://nominatim.openstreetmap.org/reverse?addressdetails=1&format=json&lat=1000&lon=1000', + server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), [200, { 'Content-Type': 'application/json' }, '{"error":"Unable to geocode"}']); server.respond(); expect(query(server.requests[0].url)).to.eql( {format: 'json', addressdetails: '1', lat: '1000', lon: '1000'}); - expect(callback).to.have.been.calledWith('Unable to geocode'); + expect(callback).to.have.been.calledWithExactly('Unable to geocode'); }); }); + + + describe('#search', function() { + + it('calls the given callback with the results of the search query', function() { + var callback = sinon.spy(); + nominatim.search('philadelphia', callback); + + server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/search'), + [200, { 'Content-Type': 'application/json' }, + '[{"place_id":"158484588","osm_type":"relation","osm_id":"188022","boundingbox":["39.867005","40.1379593","-75.2802976","-74.9558313"],"lat":"39.9523993","lon":"-75.1635898","display_name":"Philadelphia, Philadelphia County, Pennsylvania, United States of America","class":"place","type":"city","importance":0.83238050437778}]' + ]); + server.respond(); + + expect(query(server.requests[0].url)).to.eql({format: 'json', limit: '10'}); + expect(callback).to.have.been.calledOnce; + }); + }); + });