|
|
@ -1,5 +1,6 @@ |
|
|
|
|
|
|
|
const geojsonify = require('../../../helper/geojsonify'); |
|
|
|
|
|
|
|
|
|
|
|
var geojsonify = require('../../../helper/geojsonify'); |
|
|
|
const proxyquire = require('proxyquire').noCallThru(); |
|
|
|
|
|
|
|
|
|
|
|
module.exports.tests = {}; |
|
|
|
module.exports.tests = {}; |
|
|
|
|
|
|
|
|
|
|
@ -36,433 +37,565 @@ module.exports.tests.earth = function(test, common) { |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports.tests.geojsonify = function(test, common) { |
|
|
|
module.exports.tests.all = (test, common) => { |
|
|
|
|
|
|
|
test('bounding_box should be calculated using points when avaiable', t => { |
|
|
|
|
|
|
|
const input = [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_id: 'id 1', |
|
|
|
|
|
|
|
source: 'source 1', |
|
|
|
|
|
|
|
source_id: 'source_id 1', |
|
|
|
|
|
|
|
layer: 'layer 1', |
|
|
|
|
|
|
|
name: { |
|
|
|
|
|
|
|
default: 'name 1', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
center_point: { |
|
|
|
|
|
|
|
lat: 12.121212, |
|
|
|
|
|
|
|
lon: 21.212121 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_id: 'id 2', |
|
|
|
|
|
|
|
source: 'source 2', |
|
|
|
|
|
|
|
source_id: 'source_id 2', |
|
|
|
|
|
|
|
layer: 'layer 2', |
|
|
|
|
|
|
|
name: { |
|
|
|
|
|
|
|
default: 'name 2', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
center_point: { |
|
|
|
|
|
|
|
lat: 13.131313, |
|
|
|
|
|
|
|
lon: 31.313131 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
test('geojsonify(doc)', function(t) { |
|
|
|
const geojsonify = proxyquire('../../../helper/geojsonify', { |
|
|
|
var input = [ |
|
|
|
'./geojsonify_place_details': (params, source, dst) => { |
|
|
|
|
|
|
|
if (source._id === 'id 1') { |
|
|
|
|
|
|
|
dst.property1 = 'property 1'; |
|
|
|
|
|
|
|
dst.property2 = 'property 2'; |
|
|
|
|
|
|
|
} else if (source._id === 'id 2') { |
|
|
|
|
|
|
|
dst.property3 = 'property 3'; |
|
|
|
|
|
|
|
dst.property4 = 'property 4'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const actual = geojsonify({}, input); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expected = { |
|
|
|
|
|
|
|
type: 'FeatureCollection', |
|
|
|
|
|
|
|
features: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
type: 'Feature', |
|
|
|
|
|
|
|
geometry: { |
|
|
|
|
|
|
|
type: 'Point', |
|
|
|
|
|
|
|
coordinates: [ 21.212121, 12.121212 ] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
properties: { |
|
|
|
|
|
|
|
id: 'id 1', |
|
|
|
|
|
|
|
gid: 'source 1:layer 1:id 1', |
|
|
|
|
|
|
|
layer: 'layer 1', |
|
|
|
|
|
|
|
source: 'source 1', |
|
|
|
|
|
|
|
source_id: 'source_id 1', |
|
|
|
|
|
|
|
name: 'name 1', |
|
|
|
|
|
|
|
property1: 'property 1', |
|
|
|
|
|
|
|
property2: 'property 2' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
type: 'Feature', |
|
|
|
|
|
|
|
geometry: { |
|
|
|
|
|
|
|
type: 'Point', |
|
|
|
|
|
|
|
coordinates: [ 31.313131, 13.131313 ] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
properties: { |
|
|
|
|
|
|
|
id: 'id 2', |
|
|
|
|
|
|
|
gid: 'source 2:layer 2:id 2', |
|
|
|
|
|
|
|
layer: 'layer 2', |
|
|
|
|
|
|
|
source: 'source 2', |
|
|
|
|
|
|
|
source_id: 'source_id 2', |
|
|
|
|
|
|
|
name: 'name 2', |
|
|
|
|
|
|
|
property3: 'property 3', |
|
|
|
|
|
|
|
property4: 'property 4' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
bbox: [21.212121, 12.121212, 31.313131, 13.131313] |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.deepEquals(actual, expected); |
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('bounding_box should be calculated using polygons when avaiable', t => { |
|
|
|
|
|
|
|
const input = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
'_id': 'id1', |
|
|
|
_id: 'id 1', |
|
|
|
'_type': 'layer1', |
|
|
|
source: 'source 1', |
|
|
|
'source': 'source1', |
|
|
|
source_id: 'source_id 1', |
|
|
|
'source_id': 'source_id_1', |
|
|
|
layer: 'layer 1', |
|
|
|
'layer': 'layer1', |
|
|
|
name: { |
|
|
|
'center_point': { |
|
|
|
default: 'name 1', |
|
|
|
'lat': 51.5337144, |
|
|
|
|
|
|
|
'lon': -0.1069716 |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
'name': { |
|
|
|
bounding_box: { |
|
|
|
'default': '\'Round Midnight Jazz and Blues Bar' |
|
|
|
min_lon: 1, |
|
|
|
|
|
|
|
min_lat: 1, |
|
|
|
|
|
|
|
max_lon: 2, |
|
|
|
|
|
|
|
max_lat: 2 |
|
|
|
}, |
|
|
|
}, |
|
|
|
'housenumber': '13', |
|
|
|
center_point: { |
|
|
|
'street': 'Liverpool Road', |
|
|
|
lat: 12.121212, |
|
|
|
'postalcode': 'N1 0RW', |
|
|
|
lon: 21.212121 |
|
|
|
'country_a': 'GBR', |
|
|
|
} |
|
|
|
'country': 'United Kingdom', |
|
|
|
|
|
|
|
'dependency': 'dependency name', |
|
|
|
|
|
|
|
'region': 'Islington', |
|
|
|
|
|
|
|
'region_a': 'ISL', |
|
|
|
|
|
|
|
'macroregion': 'England', |
|
|
|
|
|
|
|
'county': 'Angel', |
|
|
|
|
|
|
|
'localadmin': 'test1', |
|
|
|
|
|
|
|
'locality': 'test2', |
|
|
|
|
|
|
|
'neighbourhood': 'test3', |
|
|
|
|
|
|
|
'category': [ |
|
|
|
|
|
|
|
'food', |
|
|
|
|
|
|
|
'nightlife' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'label': 'label for id id1' |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
'_id': 'id2', |
|
|
|
_id: 'id 2', |
|
|
|
'_type': 'layer2', |
|
|
|
source: 'source 2', |
|
|
|
'source': 'source2', |
|
|
|
source_id: 'source_id 2', |
|
|
|
'source_id': 'source_id_2', |
|
|
|
layer: 'layer 2', |
|
|
|
'layer': 'layer2', |
|
|
|
name: { |
|
|
|
'name': { |
|
|
|
default: 'name 2', |
|
|
|
'default': 'Blues Cafe' |
|
|
|
}, |
|
|
|
|
|
|
|
bounding_box: { |
|
|
|
|
|
|
|
min_lon: -3, |
|
|
|
|
|
|
|
min_lat: -3, |
|
|
|
|
|
|
|
max_lon: -1, |
|
|
|
|
|
|
|
max_lat: -1 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
center_point: { |
|
|
|
|
|
|
|
lat: 13.131313, |
|
|
|
|
|
|
|
lon: 31.313131 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const geojsonify = proxyquire('../../../helper/geojsonify', { |
|
|
|
|
|
|
|
'./geojsonify_place_details': (params, source, dst) => { |
|
|
|
|
|
|
|
if (source._id === 'id 1') { |
|
|
|
|
|
|
|
dst.property1 = 'property 1'; |
|
|
|
|
|
|
|
dst.property2 = 'property 2'; |
|
|
|
|
|
|
|
} else if (source._id === 'id 2') { |
|
|
|
|
|
|
|
dst.property3 = 'property 3'; |
|
|
|
|
|
|
|
dst.property4 = 'property 4'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const actual = geojsonify({}, input); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expected = { |
|
|
|
|
|
|
|
type: 'FeatureCollection', |
|
|
|
|
|
|
|
features: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
type: 'Feature', |
|
|
|
|
|
|
|
geometry: { |
|
|
|
|
|
|
|
type: 'Point', |
|
|
|
|
|
|
|
coordinates: [ 21.212121, 12.121212 ] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
properties: { |
|
|
|
|
|
|
|
id: 'id 1', |
|
|
|
|
|
|
|
gid: 'source 1:layer 1:id 1', |
|
|
|
|
|
|
|
layer: 'layer 1', |
|
|
|
|
|
|
|
source: 'source 1', |
|
|
|
|
|
|
|
source_id: 'source_id 1', |
|
|
|
|
|
|
|
name: 'name 1', |
|
|
|
|
|
|
|
property1: 'property 1', |
|
|
|
|
|
|
|
property2: 'property 2' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
bbox: [ 1, 1, 2, 2 ] |
|
|
|
}, |
|
|
|
}, |
|
|
|
'center_point': { |
|
|
|
{ |
|
|
|
'lat': '51.517806', |
|
|
|
type: 'Feature', |
|
|
|
'lon': '-0.101795' |
|
|
|
geometry: { |
|
|
|
|
|
|
|
type: 'Point', |
|
|
|
|
|
|
|
coordinates: [ 31.313131, 13.131313 ] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
properties: { |
|
|
|
|
|
|
|
id: 'id 2', |
|
|
|
|
|
|
|
gid: 'source 2:layer 2:id 2', |
|
|
|
|
|
|
|
layer: 'layer 2', |
|
|
|
|
|
|
|
source: 'source 2', |
|
|
|
|
|
|
|
source_id: 'source_id 2', |
|
|
|
|
|
|
|
name: 'name 2', |
|
|
|
|
|
|
|
property3: 'property 3', |
|
|
|
|
|
|
|
property4: 'property 4' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
bbox: [ -3, -3, -1, -1 ] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
bbox: [ -3, -3, 2, 2 ] |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.deepEquals(actual, expected); |
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('bounding_box should be calculated using polygons AND points when avaiable', t => { |
|
|
|
|
|
|
|
const input = [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_id: 'id 1', |
|
|
|
|
|
|
|
source: 'source 1', |
|
|
|
|
|
|
|
source_id: 'source_id 1', |
|
|
|
|
|
|
|
layer: 'layer 1', |
|
|
|
|
|
|
|
name: { |
|
|
|
|
|
|
|
default: 'name 1', |
|
|
|
}, |
|
|
|
}, |
|
|
|
'country_a': 'GBR', |
|
|
|
center_point: { |
|
|
|
'country': 'United Kingdom', |
|
|
|
lat: 12.121212, |
|
|
|
'dependency': 'dependency name', |
|
|
|
lon: 21.212121 |
|
|
|
'region': 'City And County Of The City Of London', |
|
|
|
} |
|
|
|
'region_a': 'COL', |
|
|
|
|
|
|
|
'macroregion': 'England', |
|
|
|
|
|
|
|
'county': 'Smithfield', |
|
|
|
|
|
|
|
'localadmin': 'test1', |
|
|
|
|
|
|
|
'locality': 'test2', |
|
|
|
|
|
|
|
'neighbourhood': 'test3', |
|
|
|
|
|
|
|
'label': 'label for id id2' |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
'_id': 'node:34633854', |
|
|
|
_id: 'id 2', |
|
|
|
'_type': 'venue', |
|
|
|
source: 'source 2', |
|
|
|
'source': 'openstreetmap', |
|
|
|
source_id: 'source_id 2', |
|
|
|
'source_id': 'source_id_3', |
|
|
|
layer: 'layer 2', |
|
|
|
'layer': 'venue', |
|
|
|
name: { |
|
|
|
'name': { |
|
|
|
default: 'name 2', |
|
|
|
'default': 'Empire State Building' |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
'center_point': { |
|
|
|
bounding_box: { |
|
|
|
'lat': '40.748432', |
|
|
|
min_lon: -3, |
|
|
|
'lon': '-73.985656' |
|
|
|
min_lat: -3, |
|
|
|
|
|
|
|
max_lon: -1, |
|
|
|
|
|
|
|
max_lat: -1 |
|
|
|
}, |
|
|
|
}, |
|
|
|
'country_a': 'USA', |
|
|
|
center_point: { |
|
|
|
'country': 'United States', |
|
|
|
lat: 13.131313, |
|
|
|
'dependency': 'dependency name', |
|
|
|
lon: 31.313131 |
|
|
|
'region': 'New York', |
|
|
|
} |
|
|
|
'region_a': 'NY', |
|
|
|
|
|
|
|
'county': 'New York', |
|
|
|
|
|
|
|
'borough': 'Manhattan', |
|
|
|
|
|
|
|
'locality': 'New York', |
|
|
|
|
|
|
|
'neighbourhood': 'Koreatown', |
|
|
|
|
|
|
|
'category': [ |
|
|
|
|
|
|
|
'tourism', |
|
|
|
|
|
|
|
'transport' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'label': 'label for id node:34633854' |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
var expected = { |
|
|
|
const geojsonify = proxyquire('../../../helper/geojsonify', { |
|
|
|
'type': 'FeatureCollection', |
|
|
|
'./geojsonify_place_details': (params, source, dst) => { |
|
|
|
'bbox': [ -73.985656, 40.748432, -0.101795, 51.5337144 ], |
|
|
|
if (source._id === 'id 1') { |
|
|
|
'features': [ |
|
|
|
dst.property1 = 'property 1'; |
|
|
|
|
|
|
|
dst.property2 = 'property 2'; |
|
|
|
|
|
|
|
} else if (source._id === 'id 2') { |
|
|
|
|
|
|
|
dst.property3 = 'property 3'; |
|
|
|
|
|
|
|
dst.property4 = 'property 4'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const actual = geojsonify({}, input); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expected = { |
|
|
|
|
|
|
|
type: 'FeatureCollection', |
|
|
|
|
|
|
|
features: [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
'type': 'Feature', |
|
|
|
type: 'Feature', |
|
|
|
'geometry': { |
|
|
|
geometry: { |
|
|
|
'type': 'Point', |
|
|
|
type: 'Point', |
|
|
|
'coordinates': [ |
|
|
|
coordinates: [ 21.212121, 12.121212 ] |
|
|
|
-0.1069716, |
|
|
|
|
|
|
|
51.5337144 |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
'properties': { |
|
|
|
properties: { |
|
|
|
'id': 'id1', |
|
|
|
id: 'id 1', |
|
|
|
'gid': 'source1:layer1:id1', |
|
|
|
gid: 'source 1:layer 1:id 1', |
|
|
|
'layer': 'layer1', |
|
|
|
layer: 'layer 1', |
|
|
|
'source': 'source1', |
|
|
|
source: 'source 1', |
|
|
|
'source_id': 'source_id_1', |
|
|
|
source_id: 'source_id 1', |
|
|
|
'name': '\'Round Midnight Jazz and Blues Bar', |
|
|
|
name: 'name 1', |
|
|
|
'country_a': 'GBR', |
|
|
|
property1: 'property 1', |
|
|
|
'country': 'United Kingdom', |
|
|
|
property2: 'property 2' |
|
|
|
'dependency': 'dependency name', |
|
|
|
|
|
|
|
'macroregion': 'England', |
|
|
|
|
|
|
|
'region': 'Islington', |
|
|
|
|
|
|
|
'region_a': 'ISL', |
|
|
|
|
|
|
|
'county': 'Angel', |
|
|
|
|
|
|
|
'localadmin': 'test1', |
|
|
|
|
|
|
|
'locality': 'test2', |
|
|
|
|
|
|
|
'neighbourhood': 'test3', |
|
|
|
|
|
|
|
'housenumber': '13', |
|
|
|
|
|
|
|
'street': 'Liverpool Road', |
|
|
|
|
|
|
|
'postalcode': 'N1 0RW', |
|
|
|
|
|
|
|
'category': [ |
|
|
|
|
|
|
|
'food', |
|
|
|
|
|
|
|
'nightlife' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'label': 'label for id id1' |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
'type': 'Feature', |
|
|
|
type: 'Feature', |
|
|
|
'geometry': { |
|
|
|
geometry: { |
|
|
|
'type': 'Point', |
|
|
|
type: 'Point', |
|
|
|
'coordinates': [ |
|
|
|
coordinates: [ 31.313131, 13.131313 ] |
|
|
|
-0.101795, |
|
|
|
|
|
|
|
51.517806 |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
'properties': { |
|
|
|
properties: { |
|
|
|
'id': 'id2', |
|
|
|
id: 'id 2', |
|
|
|
'gid': 'source2:layer2:id2', |
|
|
|
gid: 'source 2:layer 2:id 2', |
|
|
|
'layer': 'layer2', |
|
|
|
layer: 'layer 2', |
|
|
|
'source': 'source2', |
|
|
|
source: 'source 2', |
|
|
|
'source_id': 'source_id_2', |
|
|
|
source_id: 'source_id 2', |
|
|
|
'name': 'Blues Cafe', |
|
|
|
name: 'name 2', |
|
|
|
'country_a': 'GBR', |
|
|
|
property3: 'property 3', |
|
|
|
'country': 'United Kingdom', |
|
|
|
property4: 'property 4' |
|
|
|
'dependency': 'dependency name', |
|
|
|
}, |
|
|
|
'macroregion': 'England', |
|
|
|
bbox: [ -3, -3, -1, -1 ] |
|
|
|
'region': 'City And County Of The City Of London', |
|
|
|
} |
|
|
|
'region_a': 'COL', |
|
|
|
], |
|
|
|
'county': 'Smithfield', |
|
|
|
bbox: [ -3, -3, 21.212121, 12.121212 ] |
|
|
|
'localadmin': 'test1', |
|
|
|
}; |
|
|
|
'locality': 'test2', |
|
|
|
|
|
|
|
'neighbourhood': 'test3', |
|
|
|
t.deepEquals(actual, expected); |
|
|
|
'label': 'label for id id2' |
|
|
|
t.end(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.tests.non_optimal_conditions = (test, common) => { |
|
|
|
|
|
|
|
test('null/undefined places should log warnings and be ignored', t => { |
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const input = [ |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
undefined, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_id: 'id 1', |
|
|
|
|
|
|
|
source: 'source 1', |
|
|
|
|
|
|
|
source_id: 'source_id 1', |
|
|
|
|
|
|
|
layer: 'layer 1', |
|
|
|
|
|
|
|
name: { |
|
|
|
|
|
|
|
default: 'name 1', |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
center_point: { |
|
|
|
|
|
|
|
lat: 12.121212, |
|
|
|
|
|
|
|
lon: 21.212121 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const geojsonify = proxyquire('../../../helper/geojsonify', { |
|
|
|
|
|
|
|
'./geojsonify_place_details': (params, source, dst) => { |
|
|
|
|
|
|
|
if (source._id === 'id 1') { |
|
|
|
|
|
|
|
dst.property1 = 'property 1'; |
|
|
|
|
|
|
|
dst.property2 = 'property 2'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
'pelias-logger': logger |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const actual = geojsonify({}, input); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expected = { |
|
|
|
|
|
|
|
type: 'FeatureCollection', |
|
|
|
|
|
|
|
features: [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
'type': 'Feature', |
|
|
|
type: 'Feature', |
|
|
|
'geometry': { |
|
|
|
geometry: { |
|
|
|
'type': 'Point', |
|
|
|
type: 'Point', |
|
|
|
'coordinates': [ |
|
|
|
coordinates: [ 21.212121, 12.121212 ] |
|
|
|
-73.985656, |
|
|
|
|
|
|
|
40.748432 |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
'properties': { |
|
|
|
properties: { |
|
|
|
'id': 'node:34633854', |
|
|
|
id: 'id 1', |
|
|
|
'gid': 'openstreetmap:venue:node:34633854', |
|
|
|
gid: 'source 1:layer 1:id 1', |
|
|
|
'layer': 'venue', |
|
|
|
layer: 'layer 1', |
|
|
|
'source': 'openstreetmap', |
|
|
|
source: 'source 1', |
|
|
|
'source_id': 'source_id_3', |
|
|
|
source_id: 'source_id 1', |
|
|
|
'name': 'Empire State Building', |
|
|
|
name: 'name 1', |
|
|
|
'country_a': 'USA', |
|
|
|
property1: 'property 1', |
|
|
|
'country': 'United States', |
|
|
|
property2: 'property 2' |
|
|
|
'dependency': 'dependency name', |
|
|
|
|
|
|
|
'region': 'New York', |
|
|
|
|
|
|
|
'region_a': 'NY', |
|
|
|
|
|
|
|
'county': 'New York', |
|
|
|
|
|
|
|
'borough': 'Manhattan', |
|
|
|
|
|
|
|
'locality': 'New York', |
|
|
|
|
|
|
|
'neighbourhood': 'Koreatown', |
|
|
|
|
|
|
|
'category': [ |
|
|
|
|
|
|
|
'tourism', |
|
|
|
|
|
|
|
'transport' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'label': 'label for id node:34633854' |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
], |
|
|
|
|
|
|
|
bbox: [21.212121, 12.121212, 21.212121, 12.121212] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var json = geojsonify( {categories: 'foo'}, input ); |
|
|
|
t.deepEquals(actual, expected); |
|
|
|
|
|
|
|
t.ok(logger.isWarnMessage('No doc or center_point property')); |
|
|
|
t.deepEqual(json, expected, 'all docs mapped'); |
|
|
|
|
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('filtering out empty items', function (t) { |
|
|
|
test('places w/o center_point should log warnings and be ignored', t => { |
|
|
|
var input = [ |
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const input = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
'bounding_box': { |
|
|
|
_id: 'id 1', |
|
|
|
'min_lat': 40.6514712164, |
|
|
|
source: 'source 1', |
|
|
|
'max_lat': 40.6737320588, |
|
|
|
source_id: 'source_id 1', |
|
|
|
'min_lon': -73.8967895508, |
|
|
|
layer: 'layer 1', |
|
|
|
'max_lon': -73.8665771484 |
|
|
|
name: { |
|
|
|
}, |
|
|
|
default: 'name 1', |
|
|
|
'locality': [ |
|
|
|
} |
|
|
|
'New York' |
|
|
|
}, |
|
|
|
], |
|
|
|
{ |
|
|
|
'source': 'whosonfirst', |
|
|
|
_id: 'id 2', |
|
|
|
'layer': 'neighbourhood', |
|
|
|
source: 'source 2', |
|
|
|
'population': 173198, |
|
|
|
source_id: 'source_id 2', |
|
|
|
'popularity': 495, |
|
|
|
layer: 'layer 2', |
|
|
|
'center_point': { |
|
|
|
name: { |
|
|
|
'lon': -73.881319, |
|
|
|
default: 'name 2', |
|
|
|
'lat': 40.663303 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
'name': { |
|
|
|
|
|
|
|
'default': 'East New York' |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
'source_id': '85816607', |
|
|
|
center_point: { |
|
|
|
'category': ['government'], |
|
|
|
lat: 13.131313, |
|
|
|
'_id': '85816607', |
|
|
|
lon: 31.313131 |
|
|
|
'_type': 'neighbourhood', |
|
|
|
} |
|
|
|
'_score': 21.434, |
|
|
|
|
|
|
|
'confidence': 0.888, |
|
|
|
|
|
|
|
'country': [ |
|
|
|
|
|
|
|
'United States' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'country_gid': [ |
|
|
|
|
|
|
|
'85633793' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'country_a': [ |
|
|
|
|
|
|
|
'USA' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'dependency': [ |
|
|
|
|
|
|
|
'dependency name' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'dependency_gid': [ |
|
|
|
|
|
|
|
'dependency id' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'dependency_a': [ |
|
|
|
|
|
|
|
'dependency abbrevation' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'macroregion': [ |
|
|
|
|
|
|
|
'MacroRegion Name' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'macroregion_gid': [ |
|
|
|
|
|
|
|
'MacroRegion Id' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'macroregion_a': [ |
|
|
|
|
|
|
|
'MacroRegion Abbreviation' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'region': [ |
|
|
|
|
|
|
|
'New York' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'region_gid': [ |
|
|
|
|
|
|
|
'85688543' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'region_a': [ |
|
|
|
|
|
|
|
'NY' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'macrocounty': [ |
|
|
|
|
|
|
|
'MacroCounty Name' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'macrocounty_gid': [ |
|
|
|
|
|
|
|
'MacroCounty Id' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'macrocounty_a': [ |
|
|
|
|
|
|
|
'MacroCounty Abbreviation' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'county': [ |
|
|
|
|
|
|
|
'Kings County' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'county_gid': [ |
|
|
|
|
|
|
|
'102082361' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'county_a': [ |
|
|
|
|
|
|
|
null |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'borough': [ |
|
|
|
|
|
|
|
'Brooklyn' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'localadmin_gid': [ |
|
|
|
|
|
|
|
'404521211' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'borough_a': [ |
|
|
|
|
|
|
|
null |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'locality_gid': [ |
|
|
|
|
|
|
|
'85977539' |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'locality_a': [ |
|
|
|
|
|
|
|
null |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'neighbourhood': [], |
|
|
|
|
|
|
|
'neighbourhood_gid': [], |
|
|
|
|
|
|
|
'label': 'label for id 85816607' |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
var expected = { |
|
|
|
const geojsonify = proxyquire('../../../helper/geojsonify', { |
|
|
|
'type': 'FeatureCollection', |
|
|
|
'./geojsonify_place_details': (params, source, dst) => { |
|
|
|
'bbox': [-73.8967895508, 40.6514712164, -73.8665771484, 40.6737320588], |
|
|
|
if (source._id === 'id 2') { |
|
|
|
'features': [ |
|
|
|
dst.property3 = 'property 3'; |
|
|
|
|
|
|
|
dst.property4 = 'property 4'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
'pelias-logger': logger |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const actual = geojsonify({}, input); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expected = { |
|
|
|
|
|
|
|
type: 'FeatureCollection', |
|
|
|
|
|
|
|
features: [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
'type': 'Feature', |
|
|
|
type: 'Feature', |
|
|
|
'properties': { |
|
|
|
geometry: { |
|
|
|
'id': '85816607', |
|
|
|
type: 'Point', |
|
|
|
'gid': 'whosonfirst:neighbourhood:85816607', |
|
|
|
coordinates: [ 31.313131, 13.131313 ] |
|
|
|
'layer': 'neighbourhood', |
|
|
|
|
|
|
|
'source': 'whosonfirst', |
|
|
|
|
|
|
|
'source_id': '85816607', |
|
|
|
|
|
|
|
'name': 'East New York', |
|
|
|
|
|
|
|
'category': ['government'], |
|
|
|
|
|
|
|
'confidence': 0.888, |
|
|
|
|
|
|
|
'country': 'United States', |
|
|
|
|
|
|
|
'country_gid': '85633793', |
|
|
|
|
|
|
|
'country_a': 'USA', |
|
|
|
|
|
|
|
'dependency': 'dependency name', |
|
|
|
|
|
|
|
'dependency_gid': 'dependency id', |
|
|
|
|
|
|
|
'dependency_a': 'dependency abbrevation', |
|
|
|
|
|
|
|
'macroregion': 'MacroRegion Name', |
|
|
|
|
|
|
|
'macroregion_gid': 'MacroRegion Id', |
|
|
|
|
|
|
|
'macroregion_a': 'MacroRegion Abbreviation', |
|
|
|
|
|
|
|
'region': 'New York', |
|
|
|
|
|
|
|
'region_gid': '85688543', |
|
|
|
|
|
|
|
'region_a': 'NY', |
|
|
|
|
|
|
|
'macrocounty': 'MacroCounty Name', |
|
|
|
|
|
|
|
'macrocounty_gid': 'MacroCounty Id', |
|
|
|
|
|
|
|
'macrocounty_a': 'MacroCounty Abbreviation', |
|
|
|
|
|
|
|
'county': 'Kings County', |
|
|
|
|
|
|
|
'borough': 'Brooklyn', |
|
|
|
|
|
|
|
'county_gid': '102082361', |
|
|
|
|
|
|
|
'localadmin_gid': '404521211', |
|
|
|
|
|
|
|
'locality': 'New York', |
|
|
|
|
|
|
|
'locality_gid': '85977539', |
|
|
|
|
|
|
|
'label': 'label for id 85816607' |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588], |
|
|
|
properties: { |
|
|
|
'geometry': { |
|
|
|
id: 'id 2', |
|
|
|
'type': 'Point', |
|
|
|
gid: 'source 2:layer 2:id 2', |
|
|
|
'coordinates': [ |
|
|
|
layer: 'layer 2', |
|
|
|
-73.881319, |
|
|
|
source: 'source 2', |
|
|
|
40.663303 |
|
|
|
source_id: 'source_id 2', |
|
|
|
] |
|
|
|
name: 'name 2', |
|
|
|
|
|
|
|
property3: 'property 3', |
|
|
|
|
|
|
|
property4: 'property 4' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
], |
|
|
|
|
|
|
|
bbox: [31.313131, 13.131313, 31.313131, 13.131313] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var json = geojsonify( {categories: 'foo'}, input ); |
|
|
|
t.deepEquals(actual, expected); |
|
|
|
|
|
|
|
t.ok(logger.isWarnMessage('No doc or center_point property')); |
|
|
|
t.deepEqual(json, expected, 'all wanted properties exposed'); |
|
|
|
|
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.tests.categories = function (test, common) { |
|
|
|
test('places w/o names should log warnings and be ignored', t => { |
|
|
|
test('only set category if categories filter was used', function (t) { |
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
var input = [ |
|
|
|
|
|
|
|
|
|
|
|
const input = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
'_id': '85816607', |
|
|
|
_id: 'id 1', |
|
|
|
'bounding_box': { |
|
|
|
source: 'source 1', |
|
|
|
'min_lat': 40.6514712164, |
|
|
|
source_id: 'source_id 1', |
|
|
|
'max_lat': 40.6737320588, |
|
|
|
layer: 'layer 1', |
|
|
|
'min_lon': -73.8967895508, |
|
|
|
center_point: { |
|
|
|
'max_lon': -73.8665771484 |
|
|
|
lat: 12.121212, |
|
|
|
}, |
|
|
|
lon: 21.212121 |
|
|
|
'source': 'whosonfirst', |
|
|
|
} |
|
|
|
'layer': 'neighbourhood', |
|
|
|
}, |
|
|
|
'center_point': { |
|
|
|
{ |
|
|
|
'lon': -73.881319, |
|
|
|
_id: 'id 2', |
|
|
|
'lat': 40.663303 |
|
|
|
source: 'source 2', |
|
|
|
}, |
|
|
|
source_id: 'source_id 2', |
|
|
|
'name': { |
|
|
|
layer: 'layer 2', |
|
|
|
'default': 'East New York' |
|
|
|
name: {}, |
|
|
|
|
|
|
|
center_point: { |
|
|
|
|
|
|
|
lat: 13.131313, |
|
|
|
|
|
|
|
lon: 31.313131 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_id: 'id 3', |
|
|
|
|
|
|
|
source: 'source 3', |
|
|
|
|
|
|
|
source_id: 'source_id 3', |
|
|
|
|
|
|
|
layer: 'layer 3', |
|
|
|
|
|
|
|
name: { |
|
|
|
|
|
|
|
default: 'name 3', |
|
|
|
}, |
|
|
|
}, |
|
|
|
'source_id': '85816607', |
|
|
|
center_point: { |
|
|
|
'category': ['government'], |
|
|
|
lat: 14.141414, |
|
|
|
'label': 'label for id 85816607' |
|
|
|
lon: 41.414141 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
var expected = { |
|
|
|
const geojsonify = proxyquire('../../../helper/geojsonify', { |
|
|
|
'type': 'FeatureCollection', |
|
|
|
'./geojsonify_place_details': (params, source, dst) => { |
|
|
|
'bbox': [-73.8967895508, 40.6514712164, -73.8665771484, 40.6737320588], |
|
|
|
if (source._id === 'id 1') { |
|
|
|
'features': [ |
|
|
|
dst.property1 = 'property 1'; |
|
|
|
|
|
|
|
dst.property2 = 'property 2'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (source._id === 'id 2') { |
|
|
|
|
|
|
|
dst.property3 = 'property 3'; |
|
|
|
|
|
|
|
dst.property4 = 'property 4'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (source._id === 'id 3') { |
|
|
|
|
|
|
|
dst.property5 = 'property 5'; |
|
|
|
|
|
|
|
dst.property6 = 'property 6'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
'pelias-logger': logger |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const actual = geojsonify({}, input); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expected = { |
|
|
|
|
|
|
|
type: 'FeatureCollection', |
|
|
|
|
|
|
|
features: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
type: 'Feature', |
|
|
|
|
|
|
|
geometry: { |
|
|
|
|
|
|
|
type: 'Point', |
|
|
|
|
|
|
|
coordinates: [ 21.212121, 12.121212 ] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
properties: { |
|
|
|
|
|
|
|
id: 'id 1', |
|
|
|
|
|
|
|
gid: 'source 1:layer 1:id 1', |
|
|
|
|
|
|
|
layer: 'layer 1', |
|
|
|
|
|
|
|
source: 'source 1', |
|
|
|
|
|
|
|
source_id: 'source_id 1', |
|
|
|
|
|
|
|
property1: 'property 1', |
|
|
|
|
|
|
|
property2: 'property 2' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
'type': 'Feature', |
|
|
|
type: 'Feature', |
|
|
|
'properties': { |
|
|
|
geometry: { |
|
|
|
'id': '85816607', |
|
|
|
type: 'Point', |
|
|
|
'gid': 'whosonfirst:neighbourhood:85816607', |
|
|
|
coordinates: [ 31.313131, 13.131313 ] |
|
|
|
'layer': 'neighbourhood', |
|
|
|
|
|
|
|
'source': 'whosonfirst', |
|
|
|
|
|
|
|
'source_id': '85816607', |
|
|
|
|
|
|
|
'name': 'East New York', |
|
|
|
|
|
|
|
'category': ['government'], |
|
|
|
|
|
|
|
'label': 'label for id 85816607' |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588], |
|
|
|
properties: { |
|
|
|
'geometry': { |
|
|
|
id: 'id 2', |
|
|
|
'type': 'Point', |
|
|
|
gid: 'source 2:layer 2:id 2', |
|
|
|
'coordinates': [ |
|
|
|
layer: 'layer 2', |
|
|
|
-73.881319, |
|
|
|
source: 'source 2', |
|
|
|
40.663303 |
|
|
|
source_id: 'source_id 2', |
|
|
|
] |
|
|
|
property3: 'property 3', |
|
|
|
|
|
|
|
property4: 'property 4' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
type: 'Feature', |
|
|
|
|
|
|
|
geometry: { |
|
|
|
|
|
|
|
type: 'Point', |
|
|
|
|
|
|
|
coordinates: [ 41.414141, 14.141414 ] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
properties: { |
|
|
|
|
|
|
|
id: 'id 3', |
|
|
|
|
|
|
|
gid: 'source 3:layer 3:id 3', |
|
|
|
|
|
|
|
layer: 'layer 3', |
|
|
|
|
|
|
|
source: 'source 3', |
|
|
|
|
|
|
|
source_id: 'source_id 3', |
|
|
|
|
|
|
|
name: 'name 3', |
|
|
|
|
|
|
|
property5: 'property 5', |
|
|
|
|
|
|
|
property6: 'property 6' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
], |
|
|
|
|
|
|
|
bbox: [21.212121, 12.121212, 41.414141, 14.141414] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var json = geojsonify( {categories: 'foo'}, input ); |
|
|
|
t.deepEquals(actual, expected); |
|
|
|
|
|
|
|
t.ok(logger.isWarnMessage('doc source 1:layer 1:id 1 does not contain name.default')); |
|
|
|
t.deepEqual(json, expected, 'all wanted properties exposed'); |
|
|
|
t.ok(logger.isWarnMessage('doc source 2:layer 2:id 2 does not contain name.default')); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.all = function (tape, common) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.all = (tape, common) => { |
|
|
|
function test(name, testFunction) { |
|
|
|
function test(name, testFunction) { |
|
|
|
return tape('geojsonify: ' + name, testFunction); |
|
|
|
return tape(`geojsonify: ${name}`, testFunction); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for( var testCase in module.exports.tests ){ |
|
|
|
for( var testCase in module.exports.tests ){ |
|
|
|