|
|
|
@ -7,7 +7,7 @@ var search = require('../../../sanitiser/search'),
|
|
|
|
|
middleware = search.middleware, |
|
|
|
|
delim = ',', |
|
|
|
|
defaultError = 'invalid param \'text\': text length, must be >0', |
|
|
|
|
defaultClean = { text: 'test',
|
|
|
|
|
defaultClean = { text: 'test', |
|
|
|
|
types: { |
|
|
|
|
}, |
|
|
|
|
size: 10, |
|
|
|
@ -32,7 +32,7 @@ module.exports.tests.interface = function(test, common) {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.sanitize_invalid_text = function(test, common) { |
|
|
|
|
test('invalid text', function(t) {
|
|
|
|
|
test('invalid text', function(t) { |
|
|
|
|
var invalid = [ '', 100, null, undefined, new Date() ]; |
|
|
|
|
invalid.forEach( function( text ){ |
|
|
|
|
sanitize({ text: text }, function( err, clean ){ |
|
|
|
@ -91,7 +91,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
|
|
|
|
|
invalid: [], |
|
|
|
|
valid: [ 0, 45, 90, -0, '0', '45', '90', -181, -120, -91, 91, 120, 181 ] |
|
|
|
|
}; |
|
|
|
|
test('invalid lat', function(t) {
|
|
|
|
|
test('invalid lat', function(t) { |
|
|
|
|
lats.invalid.forEach( function( lat ){ |
|
|
|
|
sanitize({ text: 'test', lat: lat, lon: 0 }, function( err, clean ){ |
|
|
|
|
t.equal(err, 'invalid param \'lat\': must be >-90 and <90', lat + ' is an invalid latitude'); |
|
|
|
@ -100,7 +100,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
|
|
|
|
|
}); |
|
|
|
|
t.end(); |
|
|
|
|
}); |
|
|
|
|
test('valid lat', function(t) {
|
|
|
|
|
test('valid lat', function(t) { |
|
|
|
|
lats.valid.forEach( function( lat ){ |
|
|
|
|
sanitize({ text: 'test', lat: lat, lon: 0 }, function( err, clean ){ |
|
|
|
|
var expected = JSON.parse(JSON.stringify( defaultClean )); |
|
|
|
@ -117,7 +117,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
|
|
|
|
|
var lons = { |
|
|
|
|
valid: [ -381, -181, -180, -1, -0, 0, 45, 90, '-180', '0', '180', 181 ] |
|
|
|
|
}; |
|
|
|
|
test('valid lon', function(t) {
|
|
|
|
|
test('valid lon', function(t) { |
|
|
|
|
lons.valid.forEach( function( lon ){ |
|
|
|
|
sanitize({ text: 'test', lat: 0, lon: lon }, function( err, clean ){ |
|
|
|
|
var expected = JSON.parse(JSON.stringify( defaultClean )); |
|
|
|
@ -183,9 +183,9 @@ module.exports.tests.sanitize_bbox = function(test, common) {
|
|
|
|
|
'91, -181,-91,11', |
|
|
|
|
'91, -11,-91,181' |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
test('invalid bbox', function(t) {
|
|
|
|
|
test('invalid bbox', function(t) { |
|
|
|
|
bboxes.invalid.forEach( function( bbox ){ |
|
|
|
|
sanitize({ text: 'test', bbox: bbox }, function( err, clean ){ |
|
|
|
|
t.equal(err, undefined, 'no error'); |
|
|
|
@ -194,7 +194,7 @@ module.exports.tests.sanitize_bbox = function(test, common) {
|
|
|
|
|
}); |
|
|
|
|
t.end(); |
|
|
|
|
}); |
|
|
|
|
test('valid bbox', function(t) {
|
|
|
|
|
test('valid bbox', function(t) { |
|
|
|
|
bboxes.valid.forEach( function( bbox ){ |
|
|
|
|
sanitize({ text: 'test', bbox: bbox }, function( err, clean ){ |
|
|
|
|
var bboxArray = bbox.split(',').map(function(i) { |
|
|
|
@ -264,7 +264,7 @@ module.exports.tests.sanitize_details = function(test, common) {
|
|
|
|
|
t.equal(clean.details, false, 'default details set (to false)'); |
|
|
|
|
t.end(); |
|
|
|
|
}); |
|
|
|
|
});
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
var valid_values = ['true', true, 1, '1', 'yes', 'y']; |
|
|
|
@ -274,7 +274,7 @@ module.exports.tests.sanitize_details = function(test, common) {
|
|
|
|
|
t.equal(clean.details, true, 'details set to true'); |
|
|
|
|
t.end(); |
|
|
|
|
}); |
|
|
|
|
});
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
var valid_false_values = ['false', false, 0, '0', 'no', 'n']; |
|
|
|
@ -284,7 +284,7 @@ module.exports.tests.sanitize_details = function(test, common) {
|
|
|
|
|
t.equal(clean.details, false, 'details set to false'); |
|
|
|
|
t.end(); |
|
|
|
|
}); |
|
|
|
|
});
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('test default behavior', function(t) { |
|
|
|
|