-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:conveyal/isomorphic-mapzen-search
- Loading branch information
Showing
9 changed files
with
299 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.DS_Store | ||
.DS_Store | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
exports[`reverse should successfully reverse geocode and format 1`] = ` | ||
Array [ | ||
Object { | ||
"accuracy": "centroid", | ||
"address": "Takoma, Takoma Park, MD, USA", | ||
"confidence": 1, | ||
"country": "United States", | ||
"country_a": "USA", | ||
"country_gid": "whosonfirst:country:85633793", | ||
"county": "Montgomery County", | ||
"county_gid": "whosonfirst:county:102082719", | ||
"distance": 0, | ||
"gid": "whosonfirst:neighbourhood:85851759", | ||
"id": "85851759", | ||
"label": "Takoma, Takoma Park, MD, USA", | ||
"latlng": Object { | ||
"lat": 38.976745, | ||
"lon": -77.023104, | ||
}, | ||
"layer": "neighbourhood", | ||
"locality": "Takoma Park", | ||
"locality_gid": "whosonfirst:locality:85949501", | ||
"name": "Takoma", | ||
"neighbourhood": "Takoma", | ||
"neighbourhood_gid": "whosonfirst:neighbourhood:85851759", | ||
"region": "Maryland", | ||
"region_a": "MD", | ||
"region_gid": "whosonfirst:region:85688501", | ||
"source": "whosonfirst", | ||
"source_id": "85851759", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`search should successfully geocode and format 1`] = ` | ||
Array [ | ||
Object { | ||
"accuracy": "centroid", | ||
"address": "Takoma, Takoma Park, MD, USA", | ||
"confidence": 0.965, | ||
"country": "United States", | ||
"country_a": "USA", | ||
"country_gid": "whosonfirst:country:85633793", | ||
"county": "Montgomery County", | ||
"county_gid": "whosonfirst:county:102082719", | ||
"gid": "whosonfirst:neighbourhood:85851759", | ||
"id": "85851759", | ||
"label": "Takoma, Takoma Park, MD, USA", | ||
"latlng": Object { | ||
"lat": 38.976745, | ||
"lon": -77.023104, | ||
}, | ||
"layer": "neighbourhood", | ||
"locality": "Takoma Park", | ||
"locality_gid": "whosonfirst:locality:85949501", | ||
"name": "Takoma", | ||
"neighbourhood": "Takoma", | ||
"neighbourhood_gid": "whosonfirst:neighbourhood:85851759", | ||
"region": "Maryland", | ||
"region_a": "MD", | ||
"region_gid": "whosonfirst:region:85688501", | ||
"source": "whosonfirst", | ||
"source_id": "85851759", | ||
}, | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* globals describe, expect, it */ | ||
|
||
const nock = require('nock') | ||
|
||
const geocoder = require('../index.js') | ||
const mockReverseResult = require('./mock-reverse-result.json') | ||
const mockSearchResult = require('./mock-search-result.json') | ||
const mockKey = 'test-key' | ||
|
||
describe('search', () => { | ||
const searchQuery = '123 abc st' | ||
|
||
it('should successfully geocode', async () => { | ||
nock('https://search.mapzen.com/') | ||
.get(/v1\/search/) | ||
.reply(200, mockSearchResult) | ||
|
||
const result = await geocoder.search(mockKey, searchQuery) | ||
expect(result.features[0].geometry.coordinates[0]).toEqual(-77.023104) | ||
}) | ||
|
||
it('should successfully geocode and format', async () => { | ||
nock('https://search.mapzen.com/') | ||
.get(/v1\/search/) | ||
.reply(200, mockSearchResult) | ||
|
||
const result = await geocoder.search(mockKey, searchQuery, { format: true }) | ||
expect(result).toMatchSnapshot() | ||
expect(result[0].address).toEqual('Takoma, Takoma Park, MD, USA') | ||
}) | ||
}) | ||
|
||
describe('reverse', () => { | ||
const reverseQuery = { lat: 38.976745, lng: -77.023104 } | ||
|
||
it('should successfully reverse geocode', async () => { | ||
nock('https://search.mapzen.com/') | ||
.get(/v1\/reverse/) | ||
.reply(200, mockReverseResult) | ||
|
||
const result = await geocoder.reverse(mockKey, reverseQuery) | ||
expect(result.features[0].geometry.coordinates[0]).toEqual(-77.023104) | ||
}) | ||
|
||
it('should successfully reverse geocode and format', async () => { | ||
nock('https://search.mapzen.com/') | ||
.get(/v1\/reverse/) | ||
.reply(200, mockReverseResult) | ||
|
||
const result = await geocoder.reverse(mockKey, reverseQuery, { format: true }) | ||
expect(result).toMatchSnapshot() | ||
expect(result[0].address).toEqual('Takoma, Takoma Park, MD, USA') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"geocoding": { | ||
"version": "0.2", | ||
"attribution": "https://search.mapzen.com/v1/attribution", | ||
"query": { | ||
"size": 10, | ||
"private": false, | ||
"point.lat": 38.976745, | ||
"point.lon": -77.023104, | ||
"boundary.circle.radius": 1, | ||
"boundary.circle.lat": 38.976745, | ||
"boundary.circle.lon": -77.023104, | ||
"querySize": 20 | ||
}, | ||
"engine": { | ||
"name": "Pelias", | ||
"author": "Mapzen", | ||
"version": "1.0" | ||
}, | ||
"timestamp": 1481582055662 | ||
}, | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
-77.023104, | ||
38.976745 | ||
] | ||
}, | ||
"properties": { | ||
"id": "85851759", | ||
"gid": "whosonfirst:neighbourhood:85851759", | ||
"layer": "neighbourhood", | ||
"source": "whosonfirst", | ||
"source_id": "85851759", | ||
"name": "Takoma", | ||
"confidence": 1, | ||
"distance": 0, | ||
"accuracy": "centroid", | ||
"country": "United States", | ||
"country_gid": "whosonfirst:country:85633793", | ||
"country_a": "USA", | ||
"region": "Maryland", | ||
"region_gid": "whosonfirst:region:85688501", | ||
"region_a": "MD", | ||
"county": "Montgomery County", | ||
"county_gid": "whosonfirst:county:102082719", | ||
"locality": "Takoma Park", | ||
"locality_gid": "whosonfirst:locality:85949501", | ||
"neighbourhood": "Takoma", | ||
"neighbourhood_gid": "whosonfirst:neighbourhood:85851759", | ||
"label": "Takoma, Takoma Park, MD, USA" | ||
}, | ||
"bbox": [ | ||
-77.017242, | ||
38.973896, | ||
-77.012062, | ||
38.980594 | ||
] | ||
} | ||
], | ||
"bbox": [ | ||
-77.023234, | ||
38.973896, | ||
-77.012062, | ||
38.980594 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"geocoding": { | ||
"version": "0.2", | ||
"attribution": "https://search.mapzen.com/v1/attribution", | ||
"query": { | ||
"text": "takoma", | ||
"size": 10, | ||
"sources": [ | ||
"geonames", | ||
"openaddresses", | ||
"openstreetmap", | ||
"whosonfirst" | ||
], | ||
"private": false, | ||
"boundary.circle.radius": 25, | ||
"boundary.circle.lat": 38.8886, | ||
"boundary.circle.lon": -77.043, | ||
"querySize": 20 | ||
}, | ||
"engine": { | ||
"name": "Pelias", | ||
"author": "Mapzen", | ||
"version": "1.0" | ||
}, | ||
"timestamp": 1479272483487 | ||
}, | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
-77.023104, | ||
38.976745 | ||
] | ||
}, | ||
"properties": { | ||
"id": "85851759", | ||
"gid": "whosonfirst:neighbourhood:85851759", | ||
"layer": "neighbourhood", | ||
"source": "whosonfirst", | ||
"source_id": "85851759", | ||
"name": "Takoma", | ||
"confidence": 0.965, | ||
"accuracy": "centroid", | ||
"country": "United States", | ||
"country_gid": "whosonfirst:country:85633793", | ||
"country_a": "USA", | ||
"region": "Maryland", | ||
"region_gid": "whosonfirst:region:85688501", | ||
"region_a": "MD", | ||
"county": "Montgomery County", | ||
"county_gid": "whosonfirst:county:102082719", | ||
"locality": "Takoma Park", | ||
"locality_gid": "whosonfirst:locality:85949501", | ||
"neighbourhood": "Takoma", | ||
"neighbourhood_gid": "whosonfirst:neighbourhood:85851759", | ||
"label": "Takoma, Takoma Park, MD, USA" | ||
}, | ||
"bbox": [ | ||
-77.017242, | ||
38.973896, | ||
-77.012062, | ||
38.980594 | ||
] | ||
} | ||
], | ||
"bbox": [ | ||
-77.017897, | ||
38.904, | ||
-76.978642, | ||
39.001084 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.