|
|
@ -4,6 +4,7 @@ |
|
|
|
var reverse = require('../../../sanitizer/reverse'), |
|
|
|
var reverse = require('../../../sanitizer/reverse'), |
|
|
|
sanitize = reverse.sanitize, |
|
|
|
sanitize = reverse.sanitize, |
|
|
|
middleware = reverse.middleware, |
|
|
|
middleware = reverse.middleware, |
|
|
|
|
|
|
|
sanitizer_list = reverse.sanitizer_list, |
|
|
|
defaults = require('../../../query/reverse_defaults'), |
|
|
|
defaults = require('../../../query/reverse_defaults'), |
|
|
|
defaultError = 'missing param \'lat\'', |
|
|
|
defaultError = 'missing param \'lat\'', |
|
|
|
defaultClean = { 'point.lat': 0, |
|
|
|
defaultClean = { 'point.lat': 0, |
|
|
@ -23,7 +24,7 @@ module.exports.tests = {}; |
|
|
|
module.exports.tests.interface = function(test, common) { |
|
|
|
module.exports.tests.interface = function(test, common) { |
|
|
|
test('sanitize interface', function(t) { |
|
|
|
test('sanitize interface', function(t) { |
|
|
|
t.equal(typeof sanitize, 'function', 'sanitize is a function'); |
|
|
|
t.equal(typeof sanitize, 'function', 'sanitize is a function'); |
|
|
|
t.equal(sanitize.length, 2, 'sanitize interface'); |
|
|
|
t.equal(sanitize.length, 3, 'sanitize interface takes one param: req'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
test('middleware interface', function(t) { |
|
|
|
test('middleware interface', function(t) { |
|
|
@ -52,7 +53,7 @@ module.exports.tests.sanitize_lat = function(test, common) { |
|
|
|
test('invalid lat', function(t) { |
|
|
|
test('invalid lat', function(t) { |
|
|
|
lats.invalid.forEach( function( lat ){ |
|
|
|
lats.invalid.forEach( function( lat ){ |
|
|
|
var req = { query: { 'point.lat': lat, 'point.lon': 0 } }; |
|
|
|
var req = { query: { 'point.lat': lat, 'point.lon': 0 } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.errors[0], 'invalid param \'point.lat\': must be >-90 and <90', lat + ' is an invalid latitude'); |
|
|
|
t.equal(req.errors[0], 'invalid param \'point.lat\': must be >-90 and <90', lat + ' is an invalid latitude'); |
|
|
|
t.deepEqual(req.clean, emptyClean, 'clean only has default values set'); |
|
|
|
t.deepEqual(req.clean, emptyClean, 'clean only has default values set'); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -62,7 +63,7 @@ module.exports.tests.sanitize_lat = function(test, common) { |
|
|
|
test('valid lat', function(t) { |
|
|
|
test('valid lat', function(t) { |
|
|
|
lats.valid.forEach( function( lat ){ |
|
|
|
lats.valid.forEach( function( lat ){ |
|
|
|
var req = { query: { 'point.lat': lat, 'point.lon': 0 } }; |
|
|
|
var req = { query: { 'point.lat': lat, 'point.lon': 0 } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
var expected_lat = parseFloat( lat ); |
|
|
|
var expected_lat = parseFloat( lat ); |
|
|
|
t.deepEqual(req.errors, [], 'no errors'); |
|
|
|
t.deepEqual(req.errors, [], 'no errors'); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -72,7 +73,7 @@ module.exports.tests.sanitize_lat = function(test, common) { |
|
|
|
test('missing lat', function(t) { |
|
|
|
test('missing lat', function(t) { |
|
|
|
lats.missing.forEach( function( lat ){ |
|
|
|
lats.missing.forEach( function( lat ){ |
|
|
|
var req = { query: { 'point.lat': lat, 'point.lon': 0 } }; |
|
|
|
var req = { query: { 'point.lat': lat, 'point.lon': 0 } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.errors[0], 'missing param \'point.lat\'', 'latitude is a required field'); |
|
|
|
t.equal(req.errors[0], 'missing param \'point.lat\'', 'latitude is a required field'); |
|
|
|
t.deepEqual(req.clean, emptyClean, 'clean only has default values set'); |
|
|
|
t.deepEqual(req.clean, emptyClean, 'clean only has default values set'); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -89,7 +90,7 @@ module.exports.tests.sanitize_lon = function(test, common) { |
|
|
|
test('valid lon', function(t) { |
|
|
|
test('valid lon', function(t) { |
|
|
|
lons.valid.forEach( function( lon ){ |
|
|
|
lons.valid.forEach( function( lon ){ |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': lon } }; |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': lon } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
var expected_lon = parseFloat( lon ); |
|
|
|
var expected_lon = parseFloat( lon ); |
|
|
|
t.deepEqual(req.errors, [], 'no errors'); |
|
|
|
t.deepEqual(req.errors, [], 'no errors'); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -102,7 +103,7 @@ module.exports.tests.sanitize_lon = function(test, common) { |
|
|
|
|
|
|
|
|
|
|
|
// @todo: why is lat set?
|
|
|
|
// @todo: why is lat set?
|
|
|
|
var expected = { 'point.lat': 0, private: false, size: 10 }; |
|
|
|
var expected = { 'point.lat': 0, private: false, size: 10 }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.errors[0], 'missing param \'point.lon\'', 'longitude is a required field'); |
|
|
|
t.equal(req.errors[0], 'missing param \'point.lon\'', 'longitude is a required field'); |
|
|
|
t.deepEqual(req.clean, expected, 'clean only has default values set'); |
|
|
|
t.deepEqual(req.clean, expected, 'clean only has default values set'); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -114,21 +115,21 @@ module.exports.tests.sanitize_lon = function(test, common) { |
|
|
|
module.exports.tests.sanitize_size = function(test, common) { |
|
|
|
module.exports.tests.sanitize_size = function(test, common) { |
|
|
|
test('invalid size value', function(t) { |
|
|
|
test('invalid size value', function(t) { |
|
|
|
var req = { query: { size: 'a', 'point.lat': 0, 'point.lon': 0 } }; |
|
|
|
var req = { query: { size: 'a', 'point.lat': 0, 'point.lon': 0 } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.clean.size, 10, 'default size set'); |
|
|
|
t.equal(req.clean.size, 10, 'default size set'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
test('below min size value', function(t) { |
|
|
|
test('below min size value', function(t) { |
|
|
|
var req = { query: { size: -100, 'point.lat': 0, 'point.lon': 0 } }; |
|
|
|
var req = { query: { size: -100, 'point.lat': 0, 'point.lon': 0 } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.clean.size, 1, 'min size set'); |
|
|
|
t.equal(req.clean.size, 1, 'min size set'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
test('above max size value', function(t) { |
|
|
|
test('above max size value', function(t) { |
|
|
|
var req = { query: { size: 9999, 'point.lat': 0, 'point.lon': 0 } }; |
|
|
|
var req = { query: { size: 9999, 'point.lat': 0, 'point.lon': 0 } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.clean.size, 40, 'max size set'); |
|
|
|
t.equal(req.clean.size, 40, 'max size set'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -140,7 +141,7 @@ module.exports.tests.sanitize_private = function(test, common) { |
|
|
|
invalid_values.forEach(function(value) { |
|
|
|
invalid_values.forEach(function(value) { |
|
|
|
test('invalid private param ' + value, function(t) { |
|
|
|
test('invalid private param ' + value, function(t) { |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': 0, 'private': value } }; |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': 0, 'private': value } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.clean.private, false, 'default private set (to false)'); |
|
|
|
t.equal(req.clean.private, false, 'default private set (to false)'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -151,7 +152,7 @@ module.exports.tests.sanitize_private = function(test, common) { |
|
|
|
valid_values.forEach(function(value) { |
|
|
|
valid_values.forEach(function(value) { |
|
|
|
test('valid private param ' + value, function(t) { |
|
|
|
test('valid private param ' + value, function(t) { |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': 0, 'private': value } }; |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': 0, 'private': value } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.clean.private, true, 'private set to true'); |
|
|
|
t.equal(req.clean.private, true, 'private set to true'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -162,7 +163,7 @@ module.exports.tests.sanitize_private = function(test, common) { |
|
|
|
valid_false_values.forEach(function(value) { |
|
|
|
valid_false_values.forEach(function(value) { |
|
|
|
test('test setting false explicitly ' + value, function(t) { |
|
|
|
test('test setting false explicitly ' + value, function(t) { |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': 0, 'private': value } }; |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': 0, 'private': value } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.clean.private, false, 'private set to false'); |
|
|
|
t.equal(req.clean.private, false, 'private set to false'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -171,7 +172,7 @@ module.exports.tests.sanitize_private = function(test, common) { |
|
|
|
|
|
|
|
|
|
|
|
test('test default behavior', function(t) { |
|
|
|
test('test default behavior', function(t) { |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': 0 } }; |
|
|
|
var req = { query: { 'point.lat': 0, 'point.lon': 0 } }; |
|
|
|
sanitize(req, function(){ |
|
|
|
sanitize(req, sanitizer_list, () => { |
|
|
|
t.equal(req.clean.private, false, 'private set to false'); |
|
|
|
t.equal(req.clean.private, false, 'private set to false'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -193,7 +194,7 @@ module.exports.tests.middleware_success = function(test, common) { |
|
|
|
module.exports.all = function (tape, common) { |
|
|
|
module.exports.all = function (tape, common) { |
|
|
|
|
|
|
|
|
|
|
|
function test(name, testFunction) { |
|
|
|
function test(name, testFunction) { |
|
|
|
return tape('SANTIZE /reverse ' + name, testFunction); |
|
|
|
return tape('SANITIZE /reverse ' + name, testFunction); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for( var testCase in module.exports.tests ){ |
|
|
|
for( var testCase in module.exports.tests ){ |
|
|
|