From 71499cd201c54cf5ae7ae8c9f8f5f70d4affe578 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Thu, 16 Apr 2015 14:13:40 -0400 Subject: [PATCH] flipping default behavior - by default its details=true --- sanitiser/_details.js | 4 ++++ test/unit/sanitiser/doc.js | 10 +++++----- test/unit/sanitiser/search.js | 4 ++-- test/unit/sanitiser/suggest.js | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sanitiser/_details.js b/sanitiser/_details.js index db66478d..0e45b8cb 100644 --- a/sanitiser/_details.js +++ b/sanitiser/_details.js @@ -4,6 +4,10 @@ function sanitize( req, default_value ){ var clean = req.clean || {}; var params= req.query; + if (default_value === undefined) { + default_value = true; + } + default_value = !!default_value; // ensure the input params are a valid object diff --git a/test/unit/sanitiser/doc.js b/test/unit/sanitiser/doc.js index 08c43191..c44f8808 100644 --- a/test/unit/sanitiser/doc.js +++ b/test/unit/sanitiser/doc.js @@ -10,7 +10,7 @@ var doc = require('../../../sanitiser/doc'), defaultMissingTypeError = function(input) { var type = input.split(delimiter)[0]; return type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']'; }, - defaultClean = { ids: [ { id: '123', type: 'geoname' } ], details: false }, + defaultClean = { ids: [ { id: '123', type: 'geoname' } ], details: true }, sanitize = function(query, cb) { _sanitize({'query':query}, cb); }, inputs = { valid: [ 'geoname:1', 'osmnode:2', 'admin0:53', 'osmway:44', 'geoname:5' ], @@ -56,7 +56,7 @@ module.exports.tests.sanitize_id = function(test, common) { test('valid input', function(t) { inputs.valid.forEach( function( input ){ var input_parts = input.split(delimiter); - var expected = { ids: [ { id: input_parts[1], type: input_parts[0] } ], details: false }; + var expected = { ids: [ { id: input_parts[1], type: input_parts[0] } ], details: true }; sanitize({ id: input }, function( err, clean ){ t.equal(err, undefined, 'no error (' + input + ')' ); t.deepEqual(clean, expected, 'clean set correctly (' + input + ')'); @@ -94,7 +94,7 @@ module.exports.tests.sanitize_ids = function(test, common) { var input_parts = input.split(delimiter); expected.ids.push({ id: input_parts[1], type: input_parts[0] }); }); - expected.details = false; + expected.details = true; sanitize({ id: inputs.valid }, function( err, clean ){ t.equal(err, undefined, 'no error' ); t.deepEqual(clean, expected, 'clean set correctly'); @@ -136,14 +136,14 @@ module.exports.tests.sanitize_details = function(test, common) { test('test default behavior', function(t) { sanitize({ id:'geoname:123' }, function( err, clean ){ - t.equal(clean.details, false, 'details set to false'); + t.equal(clean.details, true, 'details set to true'); t.end(); }); }); }; module.exports.tests.de_dupe = function(test, common) { - var expected = { ids: [ { id: '1', type: 'geoname' }, { id: '2', type: 'osmnode' } ], details: false }; + var expected = { ids: [ { id: '1', type: 'geoname' }, { id: '2', type: 'osmnode' } ], details: true }; test('duplicate ids', function(t) { sanitize( { id: ['geoname:1', 'osmnode:2', 'geoname:1'] }, function( err, clean ){ t.equal(err, undefined, 'no error' ); diff --git a/test/unit/sanitiser/search.js b/test/unit/sanitiser/search.js index 3da6a46b..c710c600 100644 --- a/test/unit/sanitiser/search.js +++ b/test/unit/sanitiser/search.js @@ -8,7 +8,7 @@ var search = require('../../../sanitiser/search'), layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood', 'locality', 'local_admin', 'osmaddress', 'openaddresses' ], size: 10, - details: false + details: true }, sanitize = function(query, cb) { _sanitize({'query':query}, cb); }; @@ -300,7 +300,7 @@ module.exports.tests.sanitize_details = function(test, common) { test('test default behavior', function(t) { sanitize({ input: 'test', lat: 0, lon: 0 }, function( err, clean ){ - t.equal(clean.details, false, 'details set to false'); + t.equal(clean.details, true, 'details set to true'); t.end(); }); }); diff --git a/test/unit/sanitiser/suggest.js b/test/unit/sanitiser/suggest.js index ace639bc..d9267344 100644 --- a/test/unit/sanitiser/suggest.js +++ b/test/unit/sanitiser/suggest.js @@ -10,7 +10,7 @@ var suggest = require('../../../sanitiser/suggest'), 'locality', 'local_admin', 'osmaddress', 'openaddresses' ], lon: 0, size: 10, - details: false + details: true }, sanitize = function(query, cb) { _sanitize({'query':query}, cb); }; @@ -269,7 +269,7 @@ module.exports.tests.sanitize_details = function(test, common) { test('test default behavior', function(t) { sanitize({ input: 'test', lat: 0, lon: 0 }, function( err, clean ){ - t.equal(clean.details, false, 'details set to false'); + t.equal(clean.details, true, 'details set to true'); t.end(); }); });