Browse Source

Merge pull request #704 from pelias/master

Merge master into staging
pull/706/head
Julian Simioni 8 years ago committed by GitHub
parent
commit
ff57ef7a0e
  1. 13
      helper/geojsonify.js
  2. 1
      helper/geojsonify_place_details.js
  3. 83
      helper/labelGenerator.js
  4. 78
      helper/labelSchema.js
  5. 25
      middleware/assignLabels.js
  6. 1
      package.json
  7. 16
      query/autocomplete.js
  8. 8
      routes/v1.js
  9. 2
      sanitizer/_geo_autocomplete.js
  10. 37
      test/ciao/autocomplete/boundary_rect_valid.coffee
  11. 71
      test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js
  12. 404
      test/unit/helper/geojsonify.js
  13. 201
      test/unit/helper/labelGenerator_AUS.js
  14. 205
      test/unit/helper/labelGenerator_CAN.js
  15. 201
      test/unit/helper/labelGenerator_GBR.js
  16. 263
      test/unit/helper/labelGenerator_USA.js
  17. 200
      test/unit/helper/labelGenerator_default.js
  18. 127
      test/unit/helper/labelGenerator_examples.js
  19. 45
      test/unit/helper/labelSchema.js
  20. 118
      test/unit/middleware/assignLabels.js
  21. 20
      test/unit/query/autocomplete.js
  22. 8
      test/unit/run.js

13
helper/geojsonify.js

@ -1,7 +1,6 @@
var GeoJSON = require('geojson');
var extent = require('geojson-extent');
var labelGenerator = require('./labelGenerator');
var logger = require('pelias-logger').get('api');
var type_mapping = require('./type_mapping');
var _ = require('lodash');
@ -47,8 +46,6 @@ function geojsonifyPlace(params, place) {
addMetaData(place, output);
addName(place, output);
addDetails(params, place, output);
addLabel(place, output);
// map center_point for GeoJSON to work properly
// these should not show up in the final feature properties
@ -70,16 +67,6 @@ function addName(src, dst) {
dst.name = src.name.default;
}
/**
* Add region-specific label string
*
* @param {object} src
* @param {object} dst
*/
function addLabel(src, dst) {
dst.label = labelGenerator(dst);
}
/**
* Add bounding box
*

1
helper/geojsonify_place_details.js

@ -41,6 +41,7 @@ var DETAILS_PROPS = [
{ name: 'neighbourhood', type: 'string' },
{ name: 'neighbourhood_gid', type: 'string' },
{ name: 'bounding_box', type: 'default' },
{ name: 'label', type: 'string' },
{ name: 'category', type: 'array', condition: checkCategoryParam }
];

83
helper/labelGenerator.js

@ -1,83 +0,0 @@
var _ = require('lodash'),
schemas = require('./labelSchema');
module.exports = function( record ){
var schema = getSchema(record.country_a);
// in virtually all cases, this will be the `name` field
var labelParts = getInitialLabel(record);
// iterate the schema
for (var field in schema) {
var valueFunction = schema[field];
labelParts.push(valueFunction(record));
}
// retain only things that are truthy
labelParts = _.compact(labelParts);
// third, dedupe and join with a comma and return
return dedupeNameAndFirstLabelElement(labelParts).join(', ');
};
function dedupeNameAndFirstLabelElement(labelParts) {
// only dedupe if a result has more than a name (the first label part)
if (labelParts.length > 1) {
// first, dedupe the name and 1st label array elements
// this is used to ensure that the `name` and first admin hierarchy elements aren't repeated
// eg - `["Lancaster", "Lancaster", "PA", "United States"]` -> `["Lancaster", "PA", "United States"]`
var deduped = _.uniq([labelParts.shift(), labelParts.shift()]);
// second, unshift the deduped parts back onto the labelParts
labelParts.unshift.apply(labelParts, deduped);
}
return labelParts;
}
function getSchema(country_a) {
if (country_a && country_a.length && schemas[country_a]) {
return schemas[country_a];
}
return schemas.default;
}
// helper function that sets a default label for non-US/CA regions and countries
function getInitialLabel(record) {
if (isRegion(record.layer) &&
isGeonamesOrWhosOnFirst(record.source) &&
isUSAOrCAN(record.country_a)) {
return [];
}
if (isCountry(record.layer)) {
return [];
}
return [record.name];
}
// this can go away once geonames is no longer supported
// https://github.com/pelias/wof-admin-lookup/issues/49
function isCountry(layer) {
return 'country' === layer;
}
function isRegion(layer) {
return 'region' === layer;
}
function isUSAOrCAN(country_a) {
return 'USA' === country_a || 'CAN' === country_a;
}
function isGeonamesOrWhosOnFirst(source) {
return 'geonames' === source || 'whosonfirst' === source;
}

78
helper/labelSchema.js

@ -1,78 +0,0 @@
var _ = require('lodash');
module.exports = {
'default': {
'local': getFirstProperty(['locality', 'localadmin']),
'country': getFirstProperty(['country'])
},
'GBR': {
'local': getFirstProperty(['locality', 'localadmin']),
'regional': getFirstProperty(['macroregion']),
'country': getFirstProperty(['country'])
},
'USA': {
'borough': getFirstProperty(['borough']),
'local': getFirstProperty(['locality', 'localadmin', 'county']),
'regional': getRegionalValue,
'country': getUSACountryValue
},
'AUS': {
'local' : getFirstProperty(['locality', 'localadmin']),
'regional' : getRegionalValue,
'country': getFirstProperty(['country'])
},
'CAN': {
'local': getFirstProperty(['locality']), // no localadmins in CAN
'regional': getRegionalValue,
'country': getFirstProperty(['country'])
}
};
// find the first field of record that has a non-empty value that's not already in labelParts
function getFirstProperty(fields) {
return function(record) {
for (var i = 0; i < fields.length; i++) {
var fieldValue = record[fields[i]];
if (!_.isEmpty(fieldValue)) {
return fieldValue;
}
}
};
}
// this function is exclusively used for figuring out which field to use for states/provinces
// 1. if a state/province is the most granular bit of info entered, the label should contain
// the full state/province name, eg: Pennsylvania, USA and Ontario, CA
// 2. otherwise, the state/province abbreviation should be used, eg: Lancaster, PA, USA and Bruce, ON, CA
// 3. if the abbreviation isn't available, use the full state/province name
function getRegionalValue(record) {
if ('region' === record.layer && record.region) {
// return full state name when state is the most granular piece of info
return record.region;
} else if (record.region_a) {
// otherwise just return the region code when available
return record.region_a;
} else if (record.region) {
// return the full name when there's no region code available
return record.region;
}
}
// this function returns the full name of a country if the result is in the
// country layer (for "United States" record). It returns the abbreviation
// otherwise (eg - Lancaster, PA, USA).
function getUSACountryValue(record) {
if ('country' === record.layer && record.country) {
return record.country;
}
return record.country_a;
}

25
middleware/assignLabels.js

@ -0,0 +1,25 @@
var defaultLabelGenerator = require('pelias-labels');
function setup(labelGenerator) {
function middleware(req, res, next) {
return assignLabel(req, res, next, labelGenerator || defaultLabelGenerator);
}
return middleware;
}
function assignLabel(req, res, next, labelGenerator) {
// do nothing if there's nothing to process
if (!res || !res.data) {
return next();
}
res.data.forEach(function (result) {
result.label = labelGenerator(result);
});
next();
}
module.exports = setup;

1
package.json

@ -53,6 +53,7 @@
"morgan": "1.7.0",
"pelias-categories": "1.1.0",
"pelias-config": "2.3.0",
"pelias-labels": "1.4.0",
"pelias-logger": "0.1.0",
"pelias-model": "4.3.0",
"pelias-query": "8.8.0",

16
query/autocomplete.js

@ -49,6 +49,7 @@ query.score( peliasQuery.view.population( views.pop_subquery ) );
// non-scoring hard filters
query.filter( peliasQuery.view.sources );
query.filter( peliasQuery.view.layers );
query.filter( peliasQuery.view.boundary_rect );
// --------------------------------
@ -109,6 +110,19 @@ function generateQuery( clean ){
});
}
// boundary rect
if( check.number(clean['boundary.rect.min_lat']) &&
check.number(clean['boundary.rect.max_lat']) &&
check.number(clean['boundary.rect.min_lon']) &&
check.number(clean['boundary.rect.max_lon']) ){
vs.set({
'boundary:rect:top': clean['boundary.rect.max_lat'],
'boundary:rect:right': clean['boundary.rect.max_lon'],
'boundary:rect:bottom': clean['boundary.rect.min_lat'],
'boundary:rect:left': clean['boundary.rect.min_lon']
});
}
// run the address parser
if( clean.parsed_text ){
textParser( clean.parsed_text, vs );
@ -120,4 +134,4 @@ function generateQuery( clean ){
};
}
module.exports = generateQuery;
module.exports = generateQuery;

8
routes/v1.js

@ -46,7 +46,8 @@ var postProc = {
geocodeJSON: require('../middleware/geocodeJSON'),
sendJSON: require('../middleware/sendJSON'),
parseBoundingBox: require('../middleware/parseBBox'),
normalizeParentIds: require('../middleware/normalizeParentIds')
normalizeParentIds: require('../middleware/normalizeParentIds'),
assignLabels: require('../middleware/assignLabels')
};
/**
@ -87,6 +88,7 @@ function addRoutes(app, peliasConfig) {
postProc.renamePlacenames(),
postProc.parseBoundingBox(),
postProc.normalizeParentIds(),
postProc.assignLabels(),
postProc.geocodeJSON(peliasConfig, base),
postProc.sendJSON
]),
@ -101,6 +103,7 @@ function addRoutes(app, peliasConfig) {
postProc.renamePlacenames(),
postProc.parseBoundingBox(),
postProc.normalizeParentIds(),
postProc.assignLabels(),
postProc.geocodeJSON(peliasConfig, base),
postProc.sendJSON
]),
@ -118,6 +121,7 @@ function addRoutes(app, peliasConfig) {
postProc.renamePlacenames(),
postProc.parseBoundingBox(),
postProc.normalizeParentIds(),
postProc.assignLabels(),
postProc.geocodeJSON(peliasConfig, base),
postProc.sendJSON
]),
@ -135,6 +139,7 @@ function addRoutes(app, peliasConfig) {
postProc.renamePlacenames(),
postProc.parseBoundingBox(),
postProc.normalizeParentIds(),
postProc.assignLabels(),
postProc.geocodeJSON(peliasConfig, base),
postProc.sendJSON
]),
@ -146,6 +151,7 @@ function addRoutes(app, peliasConfig) {
postProc.renamePlacenames(),
postProc.parseBoundingBox(),
postProc.normalizeParentIds(),
postProc.assignLabels(),
postProc.geocodeJSON(peliasConfig, base),
postProc.sendJSON
]),

2
sanitizer/_geo_autocomplete.js

@ -1,5 +1,6 @@
var geo_common = require ('./_geo_common');
var LAT_LON_IS_REQUIRED = false;
var RECT_IS_REQUIRED = false;
// validate inputs, convert types and apply defaults
module.exports = function sanitize( raw, clean ){
@ -9,6 +10,7 @@ module.exports = function sanitize( raw, clean ){
try {
geo_common.sanitize_point( 'focus.point', clean, raw, LAT_LON_IS_REQUIRED );
geo_common.sanitize_rect( 'boundary.rect', clean, raw, RECT_IS_REQUIRED );
}
catch (err) {
messages.errors.push( err.message );

37
test/ciao/autocomplete/boundary_rect_valid.coffee

@ -0,0 +1,37 @@
#> focus point
path: '/v1/autocomplete?text=cairo&boundary.rect.min_lat=30&boundary.rect.max_lat=32&boundary.rect.min_lon=29&boundary.rect.max_lon=31'
#? 200 ok
response.statusCode.should.be.equal 200
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
#? valid geocoding block
should.exist json.geocoding
should.exist json.geocoding.version
should.exist json.geocoding.attribution
should.exist json.geocoding.query
should.exist json.geocoding.engine
should.exist json.geocoding.engine.name
should.exist json.geocoding.engine.author
should.exist json.geocoding.engine.version
should.exist json.geocoding.timestamp
#? valid geojson
json.type.should.be.equal 'FeatureCollection'
json.features.should.be.instanceof Array
#? expected errors
should.not.exist json.geocoding.errors
#? expected warnings
should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['text'].should.eql 'cairo'
json.geocoding.query['size'].should.eql 10
json.geocoding.query['boundary.rect.min_lat'].should.eql 30
json.geocoding.query['boundary.rect.max_lat'].should.eql 32
json.geocoding.query['boundary.rect.min_lon'].should.eql 29
json.geocoding.query['boundary.rect.max_lon'].should.eql 31

71
test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js

@ -0,0 +1,71 @@
module.exports = {
'query': {
'bool': {
'must': [{
'constant_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasQueryPartialToken',
'boost': 100,
'query': 'test',
'type': 'phrase',
'operator': 'and',
'slop': 3
}
}
}
}
}],
'should':[{
'function_score': {
'query': {
'match_all': {}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'popularity',
'missing': 1
},
'weight': 1
}]
}
},{
'function_score': {
'query': {
'match_all': {}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 3
}]
}
}],
'filter': [{
'geo_bounding_box': {
'type': 'indexed',
'center_point': {
'top': 37.83239,
'right': -122.35698,
'bottom': 37.70808,
'left': -122.51489
}
}
}]
}
},
'sort': [ '_score' ],
'size': 20,
'track_scores': true
};

404
test/unit/helper/geojsonify.js

@ -5,7 +5,7 @@ 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(typeof geojsonify, 'function', 'geojsonify is a function');
t.equal(geojsonify.length, 2, 'accepts x arguments');
t.end();
});
@ -13,22 +13,21 @@ module.exports.tests.interface = function(test, common) {
// ref: https://github.com/pelias/pelias/issues/84
module.exports.tests.earth = function(test, common) {
var earth = [{
'_type': 'geoname',
'_id': '6295630',
'source': 'whosonfirst',
'layer': 'continent',
'name': {
'default': 'Earth'
},
'center_point': {
'lon': 0,
'lat': 0
}
}];
test('earth', function(t) {
var earth = [{
'_type': 'geoname',
'_id': '6295630',
'source': 'whosonfirst',
'layer': 'continent',
'name': {
'default': 'Earth'
},
'center_point': {
'lon': 0,
'lat': 0
}
}];
t.doesNotThrow(function(){
geojsonify( {}, earth );
});
@ -39,196 +38,199 @@ module.exports.tests.earth = function(test, common) {
module.exports.tests.geojsonify = function(test, common) {
var input = [
{
'_id': 'id1',
'_type': 'layer1',
'source': 'source1',
'source_id': 'source_id_1',
'layer': 'layer1',
'center_point': {
'lat': 51.5337144,
'lon': -0.1069716
},
'name': {
'default': '\'Round Midnight Jazz and Blues Bar'
},
'housenumber': '13',
'street': 'Liverpool Road',
'postalcode': 'N1 0RW',
'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'
]
},
{
'_id': 'id2',
'_type': 'layer2',
'source': 'source2',
'source_id': 'source_id_2',
'layer': 'layer2',
'name': {
'default': 'Blues Cafe'
},
'center_point': {
'lat': '51.517806',
'lon': '-0.101795'
},
'country_a': 'GBR',
'country': 'United Kingdom',
'dependency': 'dependency name',
'region': 'City And County Of The City Of London',
'region_a': 'COL',
'macroregion': 'England',
'county': 'Smithfield',
'localadmin': 'test1',
'locality': 'test2',
'neighbourhood': 'test3'
},
{
'_id': 'node:34633854',
'_type': 'venue',
'source': 'openstreetmap',
'source_id': 'source_id_3',
'layer': 'venue',
'name': {
'default': 'Empire State Building'
},
'center_point': {
'lat': '40.748432',
'lon': '-73.985656'
},
'country_a': 'USA',
'country': 'United States',
'dependency': 'dependency name',
'region': 'New York',
'region_a': 'NY',
'county': 'New York',
'borough': 'Manhattan',
'locality': 'New York',
'neighbourhood': 'Koreatown',
'category': [
'tourism',
'transport'
]
}
];
var expected = {
'type': 'FeatureCollection',
'bbox': [ -73.985656, 40.748432, -0.101795, 51.5337144 ],
'features': [
test('geojsonify(doc)', function(t) {
var input = [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-0.1069716,
51.5337144
]
'_id': 'id1',
'_type': 'layer1',
'source': 'source1',
'source_id': 'source_id_1',
'layer': 'layer1',
'center_point': {
'lat': 51.5337144,
'lon': -0.1069716
},
'properties': {
'id': 'id1',
'gid': 'source1:layer1:id1',
'layer': 'layer1',
'source': 'source1',
'source_id': 'source_id_1',
'label': '\'Round Midnight Jazz and Blues Bar, test2, England, United Kingdom',
'name': '\'Round Midnight Jazz and Blues Bar',
'country_a': 'GBR',
'country': 'United Kingdom',
'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'
]
}
'name': {
'default': '\'Round Midnight Jazz and Blues Bar'
},
'housenumber': '13',
'street': 'Liverpool Road',
'postalcode': 'N1 0RW',
'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'
},
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-0.101795,
51.517806
]
'_id': 'id2',
'_type': 'layer2',
'source': 'source2',
'source_id': 'source_id_2',
'layer': 'layer2',
'name': {
'default': 'Blues Cafe'
},
'properties': {
'id': 'id2',
'gid': 'source2:layer2:id2',
'layer': 'layer2',
'source': 'source2',
'source_id': 'source_id_2',
'label': 'Blues Cafe, test2, England, United Kingdom',
'name': 'Blues Cafe',
'country_a': 'GBR',
'country': 'United Kingdom',
'dependency': 'dependency name',
'macroregion': 'England',
'region': 'City And County Of The City Of London',
'region_a': 'COL',
'county': 'Smithfield',
'localadmin': 'test1',
'locality': 'test2',
'neighbourhood': 'test3'
}
'center_point': {
'lat': '51.517806',
'lon': '-0.101795'
},
'country_a': 'GBR',
'country': 'United Kingdom',
'dependency': 'dependency name',
'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'
},
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-73.985656,
40.748432
]
'_id': 'node:34633854',
'_type': 'venue',
'source': 'openstreetmap',
'source_id': 'source_id_3',
'layer': 'venue',
'name': {
'default': 'Empire State Building'
},
'properties': {
'id': 'node:34633854',
'gid': 'openstreetmap:venue:node:34633854',
'layer': 'venue',
'source': 'openstreetmap',
'source_id': 'source_id_3',
'label': 'Empire State Building, Manhattan, New York, NY, USA',
'name': 'Empire State Building',
'country_a': 'USA',
'country': 'United States',
'dependency': 'dependency name',
'region': 'New York',
'region_a': 'NY',
'county': 'New York',
'borough': 'Manhattan',
'locality': 'New York',
'neighbourhood': 'Koreatown',
'category': [
'tourism',
'transport'
]
}
'center_point': {
'lat': '40.748432',
'lon': '-73.985656'
},
'country_a': 'USA',
'country': 'United States',
'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'
}
]
};
];
var expected = {
'type': 'FeatureCollection',
'bbox': [ -73.985656, 40.748432, -0.101795, 51.5337144 ],
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-0.1069716,
51.5337144
]
},
'properties': {
'id': 'id1',
'gid': 'source1:layer1:id1',
'layer': 'layer1',
'source': 'source1',
'source_id': 'source_id_1',
'name': '\'Round Midnight Jazz and Blues Bar',
'country_a': 'GBR',
'country': 'United Kingdom',
'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',
'geometry': {
'type': 'Point',
'coordinates': [
-0.101795,
51.517806
]
},
'properties': {
'id': 'id2',
'gid': 'source2:layer2:id2',
'layer': 'layer2',
'source': 'source2',
'source_id': 'source_id_2',
'name': 'Blues Cafe',
'country_a': 'GBR',
'country': 'United Kingdom',
'dependency': 'dependency name',
'macroregion': 'England',
'region': 'City And County Of The City Of London',
'region_a': 'COL',
'county': 'Smithfield',
'localadmin': 'test1',
'locality': 'test2',
'neighbourhood': 'test3',
'label': 'label for id id2'
}
},
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-73.985656,
40.748432
]
},
'properties': {
'id': 'node:34633854',
'gid': 'openstreetmap:venue:node:34633854',
'layer': 'venue',
'source': 'openstreetmap',
'source_id': 'source_id_3',
'name': 'Empire State Building',
'country_a': 'USA',
'country': 'United States',
'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'
}
}
]
};
test('geojsonify(doc)', function(t) {
var json = geojsonify( {categories: 'foo'}, input );
t.deepEqual(json, expected, 'all docs mapped');
@ -334,7 +336,8 @@ module.exports.tests.geojsonify = function(test, common) {
null
],
'neighbourhood': [],
'neighbourhood_gid': []
'neighbourhood_gid': [],
'label': 'label for id 85816607'
}
];
@ -374,7 +377,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 id 85816607'
},
'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588],
'geometry': {
@ -416,7 +419,8 @@ module.exports.tests.categories = function (test, common) {
'default': 'East New York'
},
'source_id': '85816607',
'category': ['government']
'category': ['government'],
'label': 'label for id 85816607'
}
];
@ -434,7 +438,7 @@ module.exports.tests.categories = function (test, common) {
'source_id': '85816607',
'name': 'East New York',
'category': ['government'],
'label': 'East New York'
'label': 'label for id 85816607'
},
'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588],
'geometry': {

201
test/unit/helper/labelGenerator_AUS.js

@ -1,201 +0,0 @@
var generator = require('../../../helper/labelGenerator');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof generator, 'function', 'valid function');
t.end();
});
};
module.exports.tests.australia = function(test, common) {
test('venue', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'venue name, locality name, region name, Australia');
t.end();
});
test('localadmin value should be used when locality is not available', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'venue name, localadmin name, region name, Australia');
t.end();
});
test('street', function(t) {
var doc = {
'name': 'house number street name',
'layer': 'address',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'house number street name, locality name, region name, Australia');
t.end();
});
test('neighbourhood', function(t) {
var doc = {
'name': 'neighbourhood name',
'layer': 'neighbourhood',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'neighbourhood name, locality name, region name, Australia');
t.end();
});
test('locality', function(t) {
var doc = {
'name': 'locality name',
'layer': 'locality',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'locality name, region name, Australia');
t.end();
});
test('localadmin', function(t) {
var doc = {
'name': 'localadmin name',
'layer': 'localadmin',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'localadmin name, region name, Australia');
t.end();
});
test('county', function(t) {
var doc = {
'name': 'county name',
'layer': 'county',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'county name, region name, Australia');
t.end();
});
test('macrocounty', function(t) {
var doc = {
'name': 'macrocounty name',
'layer': 'macrocounty',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'macrocounty name, region name, Australia');
t.end();
});
test('region', function(t) {
var doc = {
'name': 'region name',
'layer': 'region',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'region name, Australia');
t.end();
});
test('macroregion', function(t) {
var doc = {
'name': 'macroregion name',
'layer': 'macroregion',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'macroregion name, Australia');
t.end();
});
test('country', function(t) {
var doc = {
'name': 'Australia',
'layer': 'country',
'postalcode': 'postalcode',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'Australia');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('label generator (AUS): ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

205
test/unit/helper/labelGenerator_CAN.js

@ -1,205 +0,0 @@
var generator = require('../../../helper/labelGenerator');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof generator, 'function', 'valid function');
t.end();
});
};
module.exports.tests.canada = function(test, common) {
test('venue', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'venue name, locality name, region abbr, Canada');
t.end();
});
test('street', function(t) {
var doc = {
'name': 'house number street name',
'layer': 'address',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'house number street name, locality name, region abbr, Canada');
t.end();
});
test('neighbourhood', function(t) {
var doc = {
'name': 'neighbourhood name',
'layer': 'neighbourhood',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'neighbourhood name, locality name, region abbr, Canada');
t.end();
});
test('locality', function(t) {
var doc = {
'name': 'locality name',
'layer': 'locality',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'locality name, region abbr, Canada');
t.end();
});
test('localadmin', function(t) {
var doc = {
'name': 'localadmin name',
'layer': 'localadmin',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'localadmin name, region abbr, Canada');
t.end();
});
test('county', function(t) {
var doc = {
'name': 'county name',
'layer': 'county',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'county name, region abbr, Canada');
t.end();
});
test('macrocounty', function(t) {
var doc = {
'name': 'macrocounty name',
'layer': 'macrocounty',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'macrocounty name, region abbr, Canada');
t.end();
});
test('region', function(t) {
var doc = {
'name': 'region name',
'layer': 'region',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'region name, Canada');
t.end();
});
test('macroregion', function(t) {
var doc = {
'name': 'macroregion name',
'layer': 'macroregion',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'macroregion name, Canada');
t.end();
});
test('country', function(t) {
var doc = {
'name': 'Canada',
'layer': 'country',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'Canada');
t.end();
});
test('region should be used when region_a is not available', function(t) {
var doc = {
'name': 'locality name',
'layer': 'region',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'locality name, region name, Canada', 'region should be used');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('label generator (CAN): ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

201
test/unit/helper/labelGenerator_GBR.js

@ -1,201 +0,0 @@
var generator = require('../../../helper/labelGenerator');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof generator, 'function', 'valid function');
t.end();
});
};
module.exports.tests.united_kingdom = function(test, common) {
test('venue', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'venue name, locality name, macroregion name, United Kingdom');
t.end();
});
test('localadmin value should be used when locality is not available', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'venue name, localadmin name, macroregion name, United Kingdom');
t.end();
});
test('street', function(t) {
var doc = {
'name': 'house number street name',
'layer': 'address',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'house number street name, locality name, macroregion name, United Kingdom');
t.end();
});
test('neighbourhood', function(t) {
var doc = {
'name': 'neighbourhood name',
'layer': 'neighbourhood',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'neighbourhood name, locality name, macroregion name, United Kingdom');
t.end();
});
test('locality', function(t) {
var doc = {
'name': 'locality name',
'layer': 'locality',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'locality name, macroregion name, United Kingdom');
t.end();
});
test('localadmin', function(t) {
var doc = {
'name': 'localadmin name',
'layer': 'localadmin',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'localadmin name, macroregion name, United Kingdom');
t.end();
});
test('county', function(t) {
var doc = {
'name': 'county name',
'layer': 'county',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'county name, macroregion name, United Kingdom');
t.end();
});
test('macrocounty', function(t) {
var doc = {
'name': 'macrocounty name',
'layer': 'macrocounty',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'macrocounty name, macroregion name, United Kingdom');
t.end();
});
test('region', function(t) {
var doc = {
'name': 'region name',
'layer': 'region',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'region name, macroregion name, United Kingdom');
t.end();
});
test('macroregion', function(t) {
var doc = {
'name': 'macroregion name',
'layer': 'macroregion',
'macroregion': 'macroregion name',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'macroregion name, United Kingdom');
t.end();
});
test('country', function(t) {
var doc = {
'name': 'United Kingdom',
'layer': 'country',
'postalcode': 'postalcode',
'country_a': 'GBR',
'country': 'United Kingdom'
};
t.equal(generator(doc),'United Kingdom');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('label generator (GBR): ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

263
test/unit/helper/labelGenerator_USA.js

@ -1,263 +0,0 @@
var generator = require('../../../helper/labelGenerator');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof generator, 'function', 'valid function');
t.end();
});
};
module.exports.tests.united_states = function(test, common) {
test('venue', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'venue name, locality name, region abbr, USA');
t.end();
});
test('localadmin value should be used when there is no locality', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'venue name, localadmin name, region abbr, USA');
t.end();
});
test('county value should be used when there is no localadmin', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'venue name, county name, region abbr, USA');
t.end();
});
test('street', function(t) {
var doc = {
'name': 'house number street name',
'layer': 'address',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'house number street name, locality name, region abbr, USA');
t.end();
});
test('neighbourhood', function(t) {
var doc = {
'name': 'neighbourhood name',
'layer': 'neighbourhood',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'neighbourhood name, locality name, region abbr, USA');
t.end();
});
test('venue in borough', function(t) {
var doc = {
'name': 'venue name',
'layer': 'borough',
'neighbourhood': 'neighbourhood name',
'borough': 'borough name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'venue name, borough name, locality name, region abbr, USA');
t.end();
});
test('locality', function(t) {
var doc = {
'name': 'locality name',
'layer': 'locality',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'locality name, region abbr, USA');
t.end();
});
test('localadmin', function(t) {
var doc = {
'name': 'localadmin name',
'layer': 'localadmin',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'localadmin name, region abbr, USA');
t.end();
});
test('county', function(t) {
var doc = {
'name': 'county name',
'layer': 'county',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'county name, region abbr, USA');
t.end();
});
test('macrocounty', function(t) {
var doc = {
'name': 'macrocounty name',
'layer': 'macrocounty',
'macrocounty': 'macrocounty name',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'macrocounty name, region abbr, USA');
t.end();
});
test('region', function(t) {
var doc = {
'name': 'region name',
'layer': 'region',
'region_a': 'region abbr',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'region name, USA');
t.end();
});
test('macroregion', function(t) {
var doc = {
'name': 'macroregion name',
'layer': 'macroregion',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'macroregion name, USA');
t.end();
});
test('country', function(t) {
var doc = {
'name': 'United States',
'layer': 'country',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'United States');
t.end();
});
test('region should be used when region_a is not available', function(t) {
var doc = {
'name': 'locality name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'locality name, region name, USA', 'region should be used');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('label generator (USA): ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

200
test/unit/helper/labelGenerator_default.js

@ -1,200 +0,0 @@
var generator = require('../../../helper/labelGenerator');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof generator, 'function', 'valid function');
t.end();
});
};
module.exports.tests.default_country = function(test, common) {
test('venue', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'venue name, locality name, country name');
t.end();
});
test('localadmin value should be used when locality is not available', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'venue name, localadmin name, country name');
t.end();
});
test('street', function(t) {
var doc = {
'name': 'house number street name',
'layer': 'address',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'house number street name, locality name, country name');
t.end();
});
test('neighbourhood', function(t) {
var doc = {
'name': 'neighbourhood name',
'layer': 'neighbourhood',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'neighbourhood name, locality name, country name');
t.end();
});
test('locality', function(t) {
var doc = {
'name': 'locality name',
'layer': 'locality',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'locality name, country name');
t.end();
});
test('localadmin', function(t) {
var doc = {
'name': 'localadmin name',
'layer': 'localadmin',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'localadmin name, country name');
t.end();
});
test('county', function(t) {
var doc = {
'name': 'county name',
'layer': 'county',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'county name, country name');
t.end();
});
test('macrocounty', function(t) {
var doc = {
'name': 'macrocounty name',
'layer': 'macrocounty',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'macrocounty name, country name');
t.end();
});
test('region', function(t) {
var doc = {
'name': 'region name',
'layer': 'region',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'region name, country name');
t.end();
});
test('macroregion', function(t) {
var doc = {
'name': 'macroregion name',
'layer': 'macroregion',
'macroregion': 'macroregion name',
'country_a': 'country code',
'country': 'country name'
};
t.equal(generator(doc),'macroregion name, country name');
t.end();
});
test('country layer labels should only use the `country` field and not the `name`', function(t) {
var doc = {
'name': 'source country name',
'layer': 'country',
'country_a': 'country code',
'country': 'hierarchy country name'
};
t.equal(generator(doc),'hierarchy country name');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('label generator: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

127
test/unit/helper/labelGenerator_examples.js

@ -1,127 +0,0 @@
var generator = require('../../../helper/labelGenerator');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof generator, 'function', 'valid function');
t.end();
});
};
module.exports.tests.canada = function(test, common) {
test('venue', function(t) {
var doc = {
'name': 'Tim Horton\'s',
'layer': 'venue',
'housenumber': '1',
'street': 'Main St',
'neighbourhood': 'College Heights',
'locality': 'Thunder Bay',
'region_a': 'ON',
'region': 'Ontario',
'country_a': 'CAN',
'country': 'Canada'
};
t.equal(generator(doc),'Tim Horton\'s, Thunder Bay, ON, Canada');
t.end();
});
test('address', function(t) {
var doc = {
'name': '1 Main St',
'layer': 'venue',
'housenumber': '1',
'street': 'Main St',
'locality': 'Truth or Consequences',
'region_a': 'NM',
'region': 'New Mexico',
'country_a': 'USA',
'country': 'United States'
};
t.equal(generator(doc),'1 Main St, Truth or Consequences, NM, USA');
t.end();
});
};
module.exports.tests.france = function(test, common) {
test('eiffel tower', function(t) {
var doc = {
'name': 'Tour Eiffel',
'layer': 'venue',
'neighbourhood': 'Quartier du Gros-Caillou',
'locality': 'Paris',
'region': 'Paris',
'country_a': 'FRA',
'country': 'France'
};
t.equal(generator(doc),'Tour Eiffel, Paris, France');
t.end();
});
test('France street address', function(t) {
var doc = {
'name': '74 rue de rivoli',
'layer': 'address',
'housenumber': '74',
'street': 'Rue de Rivoli',
'neighbourhood': 'Quartier Saint-Merri',
'locality': 'Paris',
'region': 'Paris',
'country_a': 'FRA',
'country': 'France'
};
t.equal(generator(doc),'74 rue de rivoli, Paris, France');
t.end();
});
test('France neighbourhood', function(t) {
var doc = {
'name': 'Grange aux Belles Terrage',
'layer': 'neighbourhood',
'neighbourhood': 'Grange aux Belles Terrage',
'locality': 'Paris',
'region': 'Paris',
'country_a': 'FRA',
'country': 'France'
};
t.equal(generator(doc),'Grange aux Belles Terrage, Paris, France');
t.end();
});
test('Luxembourg (the city) in Luxembourg', function(t) {
var doc = {
'name': 'Luxembourg',
'layer': 'locality',
'locality': 'Luxembourg',
'country_a': 'LUX',
'country': 'Luxembourg'
};
// console.error(generator(doc));
t.equal(generator(doc),'Luxembourg, Luxembourg');
t.end();
});
};
module.exports.tests.name_only = function(test, common) {
test('name-only results (no admin fields) should not include extraneous comma', function(t) {
var doc = {
'name': 'Result name',
};
t.equal(generator(doc),'Result name');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('label generator (CAN): ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

45
test/unit/helper/labelSchema.js

@ -1,45 +0,0 @@
var schemas = require('../../../helper/labelSchema');
var alpha3 = require('../mock/alpha3.json');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof schemas, 'object', 'valid object');
t.equal(schemas.hasOwnProperty('default'), true, 'has default defined');
t.end();
});
};
module.exports.tests.supported_countries = function(test, common) {
test('supported countries', function(t) {
var supported_countries = Object.keys(schemas);
t.notEquals(supported_countries.indexOf('USA'), -1);
t.notEquals(supported_countries.indexOf('CAN'), -1);
t.notEquals(supported_countries.indexOf('GBR'), -1);
t.notEquals(supported_countries.indexOf('AUS'), -1);
t.notEquals(supported_countries.indexOf('default'), -1);
t.equals(supported_countries.length, 5);
t.equals(Object.keys(schemas.USA).length, 4);
t.equals(Object.keys(schemas.CAN).length, 3);
t.equals(Object.keys(schemas.GBR).length, 3);
t.equals(Object.keys(schemas.AUS).length, 3);
t.equals(Object.keys(schemas.default).length, 2);
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('schemas: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

118
test/unit/middleware/assignLabels.js

@ -0,0 +1,118 @@
var proxyquire = require('proxyquire').noCallThru();
module.exports.tests = {};
module.exports.tests.serialization = function(test, common) {
test('undefined res should not throw an exception', function(t) {
var assignLabels = require('../../../middleware/assignLabels')(function(){});
function testIt() {
assignLabels(undefined, {}, function() {});
}
t.doesNotThrow(testIt, 'an exception should not have been thrown');
t.end();
});
test('res without data should not throw an exception', function(t) {
var assignLabels = require('../../../middleware/assignLabels')(function(){});
function testIt() {
assignLabels({}, {}, function() {});
}
t.doesNotThrow(testIt, 'an exception should not have been thrown');
t.end();
});
test('labels should be assigned to all results', function(t) {
var labelGenerator = function(result) {
if (result.id === 1) {
return 'label 1';
}
if (result.id === 2) {
return 'label 2';
}
};
var assignLabels = require('../../../middleware/assignLabels')(labelGenerator);
var input = {
data: [
{
id: 1
},
{
id: 2
}
]
};
var expected = {
data: [
{
id: 1,
label: 'label 1'
},
{
id: 2,
label: 'label 2'
}
]
};
assignLabels({}, input, function () {
t.deepEqual(input, expected);
t.end();
});
});
test('no explicit labelGenerator supplied should use pelias-labels module', function(t) {
var assignLabels = proxyquire('../../../middleware/assignLabels', {
'pelias-labels': function(result) {
if (result.id === 1) {
return 'label 1';
}
}
})();
var input = {
data: [
{
id: 1
}
]
};
var expected = {
data: [
{
id: 1,
label: 'label 1'
}
]
};
assignLabels({}, input, function () {
t.deepEqual(input, expected);
t.end();
});
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('[middleware] assignLabels: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

20
test/unit/query/autocomplete.js

@ -189,6 +189,26 @@ module.exports.tests.query = function(test, common) {
t.deepEqual(compiled.body, expected, 'autocomplete: valid boundary.country query');
t.end();
});
test('autocomplete + bbox around San Francisco', function(t) {
var query = generate({
text: 'test',
'boundary.rect.max_lat': 37.83239,
'boundary.rect.max_lon': -122.35698,
'boundary.rect.min_lat': 37.70808,
'boundary.rect.min_lon': -122.51489,
tokens: ['test'],
tokens_complete: [],
tokens_incomplete: ['test']
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_bbox_san_francisco');
t.deepEqual(compiled.type, 'autocomplete', 'query type set');
t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_focus_null_island');
t.end();
});
};
module.exports.all = function (tape, common) {

8
test/unit/run.js

@ -14,18 +14,12 @@ var tests = [
require('./controller/search'),
require('./helper/diffPlaces'),
require('./helper/geojsonify'),
require('./helper/labelGenerator_examples'),
require('./helper/labelGenerator_default'),
require('./helper/labelGenerator_CAN'),
require('./helper/labelGenerator_AUS'),
require('./helper/labelGenerator_GBR'),
require('./helper/labelGenerator_USA'),
require('./helper/labelSchema'),
require('./helper/logging'),
require('./helper/type_mapping'),
require('./helper/sizeCalculator'),
require('./middleware/access_log'),
require('./middleware/accuracy'),
require('./middleware/assignLabels'),
require('./middleware/confidenceScore'),
require('./middleware/confidenceScoreFallback'),
require('./middleware/confidenceScoreReverse'),

Loading…
Cancel
Save