Browse Source

Fix longitude-sanitization tests.

test/unit/sanitiser/(search, suggest, reverse).js
	-Update/fix all of the tests that started failing as a result of
	the removal of longitude sanitization in 90a7683.
pull/178/head
Severyn Kozak 10 years ago committed by Julian Simioni
parent
commit
762ef85f5c
  1. 21
      test/unit/sanitiser/reverse.js
  2. 15
      test/unit/sanitiser/search.js
  3. 15
      test/unit/sanitiser/suggest.js

21
test/unit/sanitiser/reverse.js

@ -3,7 +3,7 @@ var suggest = require('../../../sanitiser/reverse'),
_sanitize = suggest.sanitize, _sanitize = suggest.sanitize,
middleware = suggest.middleware, middleware = suggest.middleware,
delim = ',', delim = ',',
defaultError = 'missing param \'lat\': must be >-90 and <90', defaultError = 'missing param \'lat\'',
defaultClean = { lat:0, defaultClean = { lat:0,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood', layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ], 'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
@ -59,7 +59,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 ){
sanitize({ lat: lat, lon: 0 }, function( err, clean ){ sanitize({ lat: lat, lon: 0 }, function( err, clean ){
t.equal(err, 'missing param \'lat\': must be >-90 and <90', 'latitude is a required field'); t.equal(err, 'missing param \'lat\'', 'latitude is a required field');
t.equal(clean, undefined, 'clean not set'); t.equal(clean, undefined, 'clean not set');
}); });
}); });
@ -69,20 +69,9 @@ module.exports.tests.sanitize_lat = function(test, common) {
module.exports.tests.sanitize_lon = function(test, common) { module.exports.tests.sanitize_lon = function(test, common) {
var lons = { var lons = {
invalid: [ -360, -181, 181, 360 ], valid: [ -360, -181, 181, -180, -1, -0, 0, 45, 90, '-180', '0', '180' ],
valid: [ -180, -1, -0, 0, 45, 90, '-180', '0', '180' ],
missing: ['', undefined, null] missing: ['', undefined, null]
}; };
test('invalid lon', function(t) {
lons.invalid.forEach( function( lon ){
sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){
t.equal(err, 'invalid param \'lon\': must be >-180 and <180', lon + ' is an invalid longitude');
t.equal(clean, undefined, 'clean not set');
});
});
t.end();
});
test('valid lon', function(t) { test('valid lon', function(t) {
lons.valid.forEach( function( lon ){ lons.valid.forEach( function( lon ){
sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){ sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){
@ -97,7 +86,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
test('missing lon', function(t) { test('missing lon', function(t) {
lons.missing.forEach( function( lon ){ lons.missing.forEach( function( lon ){
sanitize({ lat: 0, lon: lon }, function( err, clean ){ sanitize({ lat: 0, lon: lon }, function( err, clean ){
t.equal(err, 'missing param \'lon\': must be >-180 and <180', 'longitude is a required field'); t.equal(err, 'missing param \'lon\'', 'longitude is a required field');
t.equal(clean, undefined, 'clean not set'); t.equal(clean, undefined, 'clean not set');
}); });
}); });
@ -287,7 +276,7 @@ module.exports.tests.middleware_failure = function(test, common) {
t.equal(code, 400, 'status set'); t.equal(code, 400, 'status set');
}}; }};
var next = function( message ){ var next = function( message ){
t.equal(message, defaultError); t.equals(message, defaultError);
t.end(); t.end();
}; };
middleware( {}, res, next ); middleware( {}, res, next );

15
test/unit/sanitiser/search.js

@ -113,19 +113,8 @@ module.exports.tests.sanitize_lat = function(test, common) {
module.exports.tests.sanitize_lon = function(test, common) { module.exports.tests.sanitize_lon = function(test, common) {
var lons = { var lons = {
invalid: [ -360, -181, 181, 360 ], valid: [ -381, -181, -180, -1, -0, 0, 45, 90, '-180', '0', '180', 181 ]
valid: [ -180, -1, -0, 0, 45, 90, '-180', '0', '180' ]
}; };
test('invalid lon', function(t) {
lons.invalid.forEach( function( lon ){
sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){
t.equal(err, 'invalid param \'lon\': must be >-180 and <180', lon + ' is an invalid longitude');
t.equal(clean, undefined, 'clean not set');
});
});
t.end();
});
test('valid lon', function(t) { test('valid lon', function(t) {
lons.valid.forEach( function( lon ){ lons.valid.forEach( function( lon ){
sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){ sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){
@ -198,7 +187,7 @@ module.exports.tests.sanitize_bbox = function(test, common) {
test('invalid bbox coordinates', function(t) { test('invalid bbox coordinates', function(t) {
bboxes.invalid_coordinates.forEach( function( bbox ){ bboxes.invalid_coordinates.forEach( function( bbox ){
sanitize({ input: 'test', bbox: bbox }, function( err, clean ){ sanitize({ input: 'test', bbox: bbox }, function( err, clean ){
t.equal(err, 'invalid bbox', bbox + ' is invalid'); t.ok(err.match(/Invalid (lat|lon)/), bbox + ' is invalid');
t.equal(clean, undefined, 'clean not set'); t.equal(clean, undefined, 'clean not set');
}); });
}); });

15
test/unit/sanitiser/suggest.js

@ -110,19 +110,8 @@ module.exports.tests.sanitize_lat = function(test, common) {
module.exports.tests.sanitize_lon = function(test, common) { module.exports.tests.sanitize_lon = function(test, common) {
var lons = { var lons = {
invalid: [ -360, -181, 181, 360 ], valid: [ -381, -181, -180, -1, -0, 0, 45, 90, '-180', '0', '180', 181 ]
valid: [ -180, -1, -0, 0, 45, 90, '-180', '0', '180' ]
}; };
test('invalid lon', function(t) {
lons.invalid.forEach( function( lon ){
sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){
t.equal(err, 'invalid param \'lon\': must be >-180 and <180', lon + ' is an invalid longitude');
t.equal(clean, undefined, 'clean not set');
});
});
t.end();
});
test('valid lon', function(t) { test('valid lon', function(t) {
lons.valid.forEach( function( lon ){ lons.valid.forEach( function( lon ){
sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){ sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){
@ -160,7 +149,7 @@ module.exports.tests.sanitize_bbox = function(test, common) {
test('invalid bbox coordinates', function(t) { test('invalid bbox coordinates', function(t) {
bboxes.invalid_coordinates.forEach( function( bbox ){ bboxes.invalid_coordinates.forEach( function( bbox ){
sanitize({ input: 'test', lat: 0, lon: 0, bbox: bbox }, function( err, clean ){ sanitize({ input: 'test', lat: 0, lon: 0, bbox: bbox }, function( err, clean ){
t.equal(err, 'invalid bbox', bbox + ' is invalid'); t.ok(err.match(/Invalid (lat|lon)/), bbox + ' is invalid');
t.equal(clean, undefined, 'clean not set'); t.equal(clean, undefined, 'clean not set');
}); });
}); });

Loading…
Cancel
Save