From 293465b90c7ebda4c751e444359ba63ce5ca5cfa Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 13 Jan 2015 16:36:48 +0000 Subject: [PATCH] add address alias and openaddresses type. change default layers to 'poi,admin'. add comments. update tests --- query/indeces.js | 3 +- sanitiser/_layers.js | 80 ++++++++++++++++++---------------- test/unit/query/indeces.js | 2 +- test/unit/sanitiser/suggest.js | 20 ++++++++- 4 files changed, 64 insertions(+), 41 deletions(-) diff --git a/query/indeces.js b/query/indeces.js index dbeacf43..57dd5617 100644 --- a/query/indeces.js +++ b/query/indeces.js @@ -8,5 +8,6 @@ module.exports = [ 'admin0', 'admin1', 'admin2', - 'neighborhood' + 'neighborhood', + 'openaddresses' ]; \ No newline at end of file diff --git a/sanitiser/_layers.js b/sanitiser/_layers.js index 38190fdc..c12d1711 100644 --- a/sanitiser/_layers.js +++ b/sanitiser/_layers.js @@ -11,46 +11,52 @@ function sanitize( req ){ params = {}; } - // which layers to query - if('string' === typeof params.layers && params.layers.length){ - - var alias_layers = ['poi', 'admin']; - var alias_indeces = indeces.concat(alias_layers); - - var layers = params.layers.split(',').map( function( layer ){ - return layer.toLowerCase(); // lowercase inputs - }); - for( var x=0; x msg.length, 'invalid error message'); t.end(); }); }); @@ -179,6 +180,13 @@ module.exports.tests.sanitize_layers = function(test, common) { t.end(); }); }); + test('address (alias) layer', function(t) { + var address_layers = ['openaddresses']; + sanitize({ layers: 'address', input: 'test', lat: 0, lon: 0 }, function( err, clean ){ + t.deepEqual(clean.layers, address_layers, 'address layers set'); + t.end(); + }); + }); test('poi alias layer plus regular layers', function(t) { var poi_layers = ['geoname','osmnode','osmway']; var reg_layers = ['admin0', 'admin1']; @@ -195,6 +203,14 @@ module.exports.tests.sanitize_layers = function(test, common) { t.end(); }); }); + test('address alias layer plus regular layers', function(t) { + var address_layers = ['openaddresses']; + var reg_layers = ['geoname', 'osmway']; + sanitize({ layers: 'address,geoname,osmway', input: 'test', lat: 0, lon: 0 }, function( err, clean ){ + t.deepEqual(clean.layers, reg_layers.concat(address_layers), 'address + regular layers set'); + t.end(); + }); + }); test('alias layer plus regular layers (no duplicates)', function(t) { var poi_layers = ['geoname','osmnode','osmway']; sanitize({ layers: 'poi,geoname,osmnode', input: 'test', lat: 0, lon: 0 }, function( err, clean ){