From 4069c992121e3353c941a18138e4b5b760bfa084 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 25 May 2016 15:29:22 -0400 Subject: [PATCH 1/5] Remove unused sanitiser test The sanitiser got removed at some point, but the tests remained. --- test/unit/sanitiser/_private.js | 53 --------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 test/unit/sanitiser/_private.js diff --git a/test/unit/sanitiser/_private.js b/test/unit/sanitiser/_private.js deleted file mode 100644 index 8cebf566..00000000 --- a/test/unit/sanitiser/_private.js +++ /dev/null @@ -1,53 +0,0 @@ -var sanitize = require('../../../sanitiser/_private'); - -module.exports.tests = {}; - -module.exports.tests.sanitize_private = function(test, common) { - var invalid_values = [null, -1, 123, NaN, 'abc']; - invalid_values.forEach(function(privateValue) { - test('invalid private param ' + privateValue, function(t) { - var req = {query: { private: privateValue }}; - sanitize(req); - t.equal(req.clean.private, false, 'default private set (to false)'); - t.end(); - }); - }); - - var valid_values = ['true', true, 1, '1', 'yes', 'y']; - valid_values.forEach(function(privateValue) { - test('valid private param ' + privateValue, function(t) { - var req = {query: { private: privateValue }}; - sanitize(req); - t.equal(req.clean.private, true, 'private set to true'); - t.end(); - }); - }); - - var valid_false_values = ['false', false, 0, '0', 'no', 'n']; - valid_false_values.forEach(function(privateValue) { - test('test setting false explicitly ' + privateValue, function(t) { - var req = {query: { private: privateValue }}; - sanitize(req); - t.equal(req.clean.private, false, 'private set to false'); - t.end(); - }); - }); - - test('test default behavior', function(t) { - var req = {query: {}}; - sanitize(req); - t.equal(req.clean.private, true, 'private set to true'); - t.end(); - }); -}; - -module.exports.all = function (tape, common) { - - function test(name, testFunction) { - return tape('SANTIZE _private ' + name, testFunction); - } - - for( var testCase in module.exports.tests ){ - module.exports.tests[testCase](test, common); - } -}; From 05baed7b51ac22b07dfa6aabdd61b99006e06b8f Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 25 May 2016 16:06:55 -0400 Subject: [PATCH 2/5] Whitespace --- sanitiser/_geo_reverse.js | 1 - test/unit/sanitiser/_geo_reverse.js | 3 --- 2 files changed, 4 deletions(-) diff --git a/sanitiser/_geo_reverse.js b/sanitiser/_geo_reverse.js index 52f2980f..9020e30d 100644 --- a/sanitiser/_geo_reverse.js +++ b/sanitiser/_geo_reverse.js @@ -1,4 +1,3 @@ - var geo_common = require ('./_geo_common'); var _ = require('lodash'); var defaults = require('../query/reverse_defaults'); diff --git a/test/unit/sanitiser/_geo_reverse.js b/test/unit/sanitiser/_geo_reverse.js index e7c62e07..632335a0 100644 --- a/test/unit/sanitiser/_geo_reverse.js +++ b/test/unit/sanitiser/_geo_reverse.js @@ -83,7 +83,6 @@ module.exports.tests.sanitize_boundary_country = function(test, common) { t.equals(raw['boundary.circle.radius'], defaults['boundary:circle:radius'], 'should be from defaults'); t.equals(clean['boundary.circle.radius'], parseFloat(defaults['boundary:circle:radius']), 'should be same as raw'); t.end(); - }); test('explicit boundary.circle.radius should be used instead of default', function(t) { @@ -98,9 +97,7 @@ module.exports.tests.sanitize_boundary_country = function(test, common) { t.equals(raw['boundary.circle.radius'], '3248732857km', 'should be parsed float'); t.equals(clean['boundary.circle.radius'], 3248732857.0, 'should be copied from raw'); t.end(); - }); - }; module.exports.all = function (tape, common) { From 16d0a8b5393828e3d935c9d8ff38ffdd686de5e9 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 25 May 2016 16:08:51 -0400 Subject: [PATCH 3/5] Rename test to clarify layers matter --- test/unit/sanitiser/_geo_reverse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/sanitiser/_geo_reverse.js b/test/unit/sanitiser/_geo_reverse.js index 632335a0..c601bc56 100644 --- a/test/unit/sanitiser/_geo_reverse.js +++ b/test/unit/sanitiser/_geo_reverse.js @@ -72,7 +72,7 @@ module.exports.tests.sanitize_boundary_country = function(test, common) { t.end(); }); - test('no boundary.circle.radius supplied should be set to default', function(t) { + test('no boundary.circle.radius and no layers supplied should be set to default', function(t) { var raw = { 'point.lat': '12.121212', 'point.lon': '21.212121' From 4acbc2a0017f774642e0d9c97f5103ff8cc130b5 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 25 May 2016 16:09:34 -0400 Subject: [PATCH 4/5] Change default reverse radius to 1km Its a little more work to support different unit types, 1km is still fine. --- query/reverse_defaults.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query/reverse_defaults.js b/query/reverse_defaults.js index 06ad6400..e5fcb3af 100644 --- a/query/reverse_defaults.js +++ b/query/reverse_defaults.js @@ -12,7 +12,7 @@ module.exports = _.merge({}, peliasQuery.defaults, { 'sort:distance:order': 'asc', 'sort:distance:distance_type': 'plane', - 'boundary:circle:radius': '500km', + 'boundary:circle:radius': '1km', 'boundary:circle:distance_type': 'plane', 'boundary:circle:optimize_bbox': 'indexed', 'boundary:circle:_cache': true, From c9d87f7b0ce944da0dbbc0b9afcaa620c4c7cb59 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 25 May 2016 16:39:10 -0400 Subject: [PATCH 5/5] Add a separate default distance for coarse reverse --- query/reverse_defaults.js | 1 + sanitiser/_geo_reverse.js | 7 ++++++- test/unit/sanitiser/_geo_reverse.js | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/query/reverse_defaults.js b/query/reverse_defaults.js index e5fcb3af..8392183f 100644 --- a/query/reverse_defaults.js +++ b/query/reverse_defaults.js @@ -13,6 +13,7 @@ module.exports = _.merge({}, peliasQuery.defaults, { 'sort:distance:distance_type': 'plane', 'boundary:circle:radius': '1km', + 'boundary:circle:radius:coarse': '500km', 'boundary:circle:distance_type': 'plane', 'boundary:circle:optimize_bbox': 'indexed', 'boundary:circle:_cache': true, diff --git a/sanitiser/_geo_reverse.js b/sanitiser/_geo_reverse.js index 9020e30d..06785c44 100644 --- a/sanitiser/_geo_reverse.js +++ b/sanitiser/_geo_reverse.js @@ -29,7 +29,12 @@ module.exports = function sanitize( raw, clean ){ // if no radius was passed, set the default if ( _.isUndefined( raw['boundary.circle.radius'] ) ) { - raw['boundary.circle.radius'] = defaults['boundary:circle:radius']; + // the default is small unless layers other than venue or address were explicitly specified + if (clean.layers && clean.layers.length > 0 && !_.includes(clean.layers, 'venue') && !_.includes(clean.layers, 'address')) { + raw['boundary.circle.radius'] = defaults['boundary:circle:radius:coarse']; + } else { + raw['boundary.circle.radius'] = defaults['boundary:circle:radius']; + } } // santize the boundary.circle diff --git a/test/unit/sanitiser/_geo_reverse.js b/test/unit/sanitiser/_geo_reverse.js index c601bc56..480d06b2 100644 --- a/test/unit/sanitiser/_geo_reverse.js +++ b/test/unit/sanitiser/_geo_reverse.js @@ -85,6 +85,32 @@ module.exports.tests.sanitize_boundary_country = function(test, common) { t.end(); }); + test('no boundary.circle.radius and coarse layers supplied should be set to coarse default', function(t) { + var raw = { + 'point.lat': '12.121212', + 'point.lon': '21.212121' + }; + var clean = { layers: 'coarse' }; + var errorsAndWarnings = sanitize(raw, clean); + + t.equals(raw['boundary.circle.radius'], defaults['boundary:circle:radius:coarse'], 'should be from defaults'); + t.equals(clean['boundary.circle.radius'], parseFloat(defaults['boundary:circle:radius:coarse']), 'should be same as raw'); + t.end(); + }); + + test('no boundary.circle.radius and coarse layer supplied should be set to coarse default', function(t) { + var raw = { + 'point.lat': '12.121212', + 'point.lon': '21.212121' + }; + var clean = { layers: 'locality' }; + var errorsAndWarnings = sanitize(raw, clean); + + t.equals(raw['boundary.circle.radius'], defaults['boundary:circle:radius:coarse'], 'should be from defaults'); + t.equals(clean['boundary.circle.radius'], parseFloat(defaults['boundary:circle:radius:coarse']), 'should be same as raw'); + t.end(); + }); + test('explicit boundary.circle.radius should be used instead of default', function(t) { var raw = { 'point.lat': '12.121212',