|
|
|
@ -5,15 +5,15 @@ module.exports.tests = {};
|
|
|
|
|
|
|
|
|
|
module.exports.tests.interface = function(test, common) { |
|
|
|
|
test('valid interface', function(t) { |
|
|
|
|
t.equal(typeof geojsonify, 'function', 'search is a function'); |
|
|
|
|
t.equal(geojsonify.length, 2, 'accepts x arguments'); |
|
|
|
|
t.equal(typeof geojsonify, 'function', 'geojsonify is a function'); |
|
|
|
|
t.equal(geojsonify.length, 3, 'accepts x arguments'); |
|
|
|
|
t.end(); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// ref: https://github.com/pelias/pelias/issues/84
|
|
|
|
|
module.exports.tests.earth = function(test, common) { |
|
|
|
|
|
|
|
|
|
test('earth', function(t) { |
|
|
|
|
var earth = [{ |
|
|
|
|
'_type': 'geoname', |
|
|
|
|
'_id': '6295630', |
|
|
|
@ -28,9 +28,12 @@ module.exports.tests.earth = function(test, common) {
|
|
|
|
|
} |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
test('earth', function(t) { |
|
|
|
|
var labelGenerator = function(doc) { |
|
|
|
|
return 'label for 6295630'; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.doesNotThrow(function(){ |
|
|
|
|
geojsonify( {}, earth ); |
|
|
|
|
geojsonify( {}, earth, labelGenerator ); |
|
|
|
|
}); |
|
|
|
|
t.end(); |
|
|
|
|
}); |
|
|
|
@ -39,6 +42,7 @@ module.exports.tests.earth = function(test, common) {
|
|
|
|
|
|
|
|
|
|
module.exports.tests.geojsonify = function(test, common) { |
|
|
|
|
|
|
|
|
|
test('geojsonify(doc)', function(t) { |
|
|
|
|
var input = [ |
|
|
|
|
{ |
|
|
|
|
'_id': 'id1', |
|
|
|
@ -143,7 +147,7 @@ module.exports.tests.geojsonify = function(test, common) {
|
|
|
|
|
'layer': 'layer1', |
|
|
|
|
'source': 'source1', |
|
|
|
|
'source_id': 'source_id_1', |
|
|
|
|
'label': '\'Round Midnight Jazz and Blues Bar, test2, England, United Kingdom', |
|
|
|
|
'label': 'label for id1', |
|
|
|
|
'name': '\'Round Midnight Jazz and Blues Bar', |
|
|
|
|
'country_a': 'GBR', |
|
|
|
|
'country': 'United Kingdom', |
|
|
|
@ -179,7 +183,7 @@ module.exports.tests.geojsonify = function(test, common) {
|
|
|
|
|
'layer': 'layer2', |
|
|
|
|
'source': 'source2', |
|
|
|
|
'source_id': 'source_id_2', |
|
|
|
|
'label': 'Blues Cafe, test2, England, United Kingdom', |
|
|
|
|
'label': 'label for id2', |
|
|
|
|
'name': 'Blues Cafe', |
|
|
|
|
'country_a': 'GBR', |
|
|
|
|
'country': 'United Kingdom', |
|
|
|
@ -208,7 +212,7 @@ module.exports.tests.geojsonify = function(test, common) {
|
|
|
|
|
'layer': 'venue', |
|
|
|
|
'source': 'openstreetmap', |
|
|
|
|
'source_id': 'source_id_3', |
|
|
|
|
'label': 'Empire State Building, Manhattan, New York, NY, USA', |
|
|
|
|
'label': 'label for node:34633854', |
|
|
|
|
'name': 'Empire State Building', |
|
|
|
|
'country_a': 'USA', |
|
|
|
|
'country': 'United States', |
|
|
|
@ -228,8 +232,20 @@ module.exports.tests.geojsonify = function(test, common) {
|
|
|
|
|
] |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
test('geojsonify(doc)', function(t) { |
|
|
|
|
var json = geojsonify( {categories: 'foo'}, input ); |
|
|
|
|
var labelGenerator = function(doc) { |
|
|
|
|
if (doc.id === 'id1') { |
|
|
|
|
return 'label for id1'; |
|
|
|
|
} |
|
|
|
|
if (doc.id === 'id2') { |
|
|
|
|
return 'label for id2'; |
|
|
|
|
} |
|
|
|
|
if (doc.id === 'node:34633854') { |
|
|
|
|
return 'label for node:34633854'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var json = geojsonify( {categories: 'foo'}, input, labelGenerator ); |
|
|
|
|
|
|
|
|
|
t.deepEqual(json, expected, 'all docs mapped'); |
|
|
|
|
t.end(); |
|
|
|
@ -374,7 +390,7 @@ module.exports.tests.geojsonify = function(test, common) {
|
|
|
|
|
'localadmin_gid': '404521211', |
|
|
|
|
'locality': 'New York', |
|
|
|
|
'locality_gid': '85977539', |
|
|
|
|
'label': 'East New York, Brooklyn, New York, NY, USA' |
|
|
|
|
'label': 'label for 85816607' |
|
|
|
|
}, |
|
|
|
|
'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588], |
|
|
|
|
'geometry': { |
|
|
|
@ -388,7 +404,13 @@ module.exports.tests.geojsonify = function(test, common) {
|
|
|
|
|
] |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var json = geojsonify( {categories: 'foo'}, input ); |
|
|
|
|
var labelGenerator = function(doc) { |
|
|
|
|
if (doc.id === '85816607') { |
|
|
|
|
return 'label for 85816607'; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var json = geojsonify( {categories: 'foo'}, input, labelGenerator ); |
|
|
|
|
|
|
|
|
|
t.deepEqual(json, expected, 'all wanted properties exposed'); |
|
|
|
|
t.end(); |
|
|
|
@ -434,7 +456,7 @@ module.exports.tests.categories = function (test, common) {
|
|
|
|
|
'source_id': '85816607', |
|
|
|
|
'name': 'East New York', |
|
|
|
|
'category': ['government'], |
|
|
|
|
'label': 'East New York' |
|
|
|
|
'label': 'label for 85816607' |
|
|
|
|
}, |
|
|
|
|
'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588], |
|
|
|
|
'geometry': { |
|
|
|
@ -448,7 +470,13 @@ module.exports.tests.categories = function (test, common) {
|
|
|
|
|
] |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var json = geojsonify( {categories: 'foo'}, input ); |
|
|
|
|
var labelGenerator = function(doc) { |
|
|
|
|
if (doc.id === '85816607') { |
|
|
|
|
return 'label for 85816607'; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var json = geojsonify( {categories: 'foo'}, input, labelGenerator ); |
|
|
|
|
|
|
|
|
|
t.deepEqual(json, expected, 'all wanted properties exposed'); |
|
|
|
|
t.end(); |
|
|
|
|