@ -73,7 +73,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
} ;
test ( 'valid lon' , function ( t ) {
lons . valid . forEach ( function ( lon ) {
sanitize ( { input : 'test' , lat : 0 , lon : lon } , function ( err , clean ) {
sanitize ( { lat : 0 , lon : lon } , function ( err , clean ) {
var expected = JSON . parse ( JSON . stringify ( defaultClean ) ) ;
expected . lon = parseFloat ( lon ) ;
t . equal ( err , undefined , 'no error' ) ;
@ -96,19 +96,19 @@ module.exports.tests.sanitize_lon = function(test, common) {
module . exports . tests . sanitize _size = function ( test , common ) {
test ( 'invalid size value' , function ( t ) {
sanitize ( { size : 'a' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { size : 'a' , lat : 0 , lon : 0 } , function ( err , clean ) {
t . equal ( clean . size , 10 , 'default size set' ) ;
t . end ( ) ;
} ) ;
} ) ;
test ( 'below min size value' , function ( t ) {
sanitize ( { size : - 100 , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { size : - 100 , lat : 0 , lon : 0 } , function ( err , clean ) {
t . equal ( clean . size , 1 , 'min size set' ) ;
t . end ( ) ;
} ) ;
} ) ;
test ( 'above max size value' , function ( t ) {
sanitize ( { size : 9999 , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { size : 9999 , lat : 0 , lon : 0 } , function ( err , clean ) {
t . equal ( clean . size , 40 , 'max size set' ) ;
t . end ( ) ;
} ) ;
@ -119,7 +119,7 @@ module.exports.tests.sanitize_details = function(test, common) {
var invalid _values = [ null , - 1 , 123 , NaN , 'abc' ] ;
invalid _values . forEach ( function ( details ) {
test ( 'invalid details param ' + details , function ( t ) {
sanitize ( { input : 'test' , lat : 0 , lon : 0 , details : details } , function ( err , clean ) {
sanitize ( { lat : 0 , lon : 0 , details : details } , function ( err , clean ) {
t . equal ( clean . details , false , 'details set to false' ) ;
t . end ( ) ;
} ) ;
@ -129,7 +129,7 @@ module.exports.tests.sanitize_details = function(test, common) {
var valid _values = [ true , 'true' , 1 , '1' , 'yes' , 'y' ] ;
valid _values . forEach ( function ( details ) {
test ( 'valid details param ' + details , function ( t ) {
sanitize ( { input : 'test' , lat : 0 , lon : 0 , details : details } , function ( err , clean ) {
sanitize ( { lat : 0 , lon : 0 , details : details } , function ( err , clean ) {
t . equal ( clean . details , true , 'details set to true' ) ;
t . end ( ) ;
} ) ;
@ -137,7 +137,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 ) {
sanitize ( { lat : 0 , lon : 0 } , function ( err , clean ) {
t . equal ( clean . details , true , 'details set to true' ) ;
t . end ( ) ;
} ) ;
@ -146,7 +146,7 @@ module.exports.tests.sanitize_details = function(test, common) {
var valid _false _values = [ 'false' , false , 0 , '0' , 'no' , 'n' ] ;
valid _false _values . forEach ( function ( details ) {
test ( 'test setting false explicitly ' + details , function ( t ) {
sanitize ( { input : 'test' , lat : 0 , lon : 0 , details : details } , function ( err , clean ) {
sanitize ( { lat : 0 , lon : 0 , details : details } , function ( err , clean ) {
t . equal ( clean . details , false , 'details set to false' ) ;
t . end ( ) ;
} ) ;
@ -156,13 +156,13 @@ module.exports.tests.sanitize_details = function(test, common) {
module . exports . tests . sanitize _layers = function ( test , common ) {
test ( 'unspecified' , function ( t ) {
sanitize ( { layers : undefined , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : undefined , lat : 0 , lon : 0 } , function ( err , clean ) {
t . deepEqual ( clean . types . from _layers , defaultClean . types . from _layers , 'default layers set' ) ;
t . end ( ) ;
} ) ;
} ) ;
test ( 'invalid layer' , function ( t ) {
sanitize ( { layers : 'test_layer' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : 'test_layer' , lat : 0 , lon : 0 } , function ( err , clean ) {
var msg = 'invalid param \'layers\': must be one or more of ' ;
t . true ( err . match ( msg ) , 'invalid layer requested' ) ;
t . true ( err . length > msg . length , 'invalid error message' ) ;
@ -171,21 +171,21 @@ module.exports.tests.sanitize_layers = function(test, common) {
} ) ;
test ( 'poi (alias) layer' , function ( t ) {
var poi _layers = [ 'geoname' , 'osmnode' , 'osmway' ] ;
sanitize ( { layers : 'poi' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : 'poi' , lat : 0 , lon : 0 } , function ( err , clean ) {
t . deepEqual ( clean . types . from _layers , poi _layers , 'poi layers set' ) ;
t . end ( ) ;
} ) ;
} ) ;
test ( 'admin (alias) layer' , function ( t ) {
var admin _layers = [ 'admin0' , 'admin1' , 'admin2' , 'neighborhood' , 'locality' , 'local_admin' ] ;
sanitize ( { layers : 'admin' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : 'admin' , lat : 0 , lon : 0 } , function ( err , clean ) {
t . deepEqual ( clean . types . from _layers , admin _layers , 'admin layers set' ) ;
t . end ( ) ;
} ) ;
} ) ;
test ( 'address (alias) layer' , function ( t ) {
var address _layers = [ 'osmaddress' , 'openaddresses' ] ;
sanitize ( { layers : 'address' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : 'address' , lat : 0 , lon : 0 } , function ( err , clean ) {
t . deepEqual ( clean . types . from _layers , address _layers , 'address layers set' ) ;
t . end ( ) ;
} ) ;
@ -193,7 +193,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
test ( 'poi alias layer plus regular layers' , function ( t ) {
var poi _layers = [ 'geoname' , 'osmnode' , 'osmway' ] ;
var reg _layers = [ 'admin0' , 'admin1' ] ;
sanitize ( { layers : 'poi,admin0,admin1' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : 'poi,admin0,admin1' , lat : 0 , lon : 0 } , function ( err , clean ) {
t . deepEqual ( clean . types . from _layers , reg _layers . concat ( poi _layers ) , 'poi + regular layers' ) ;
t . end ( ) ;
} ) ;
@ -201,7 +201,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
test ( 'admin alias layer plus regular layers' , function ( t ) {
var admin _layers = [ 'admin0' , 'admin1' , 'admin2' , 'neighborhood' , 'locality' , 'local_admin' ] ;
var reg _layers = [ 'geoname' , 'osmway' ] ;
sanitize ( { layers : 'admin,geoname,osmway' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : 'admin,geoname,osmway' , lat : 0 , lon : 0 } , function ( err , clean ) {
t . deepEqual ( clean . types . from _layers , reg _layers . concat ( admin _layers ) , 'admin + regular layers set' ) ;
t . end ( ) ;
} ) ;
@ -209,21 +209,21 @@ module.exports.tests.sanitize_layers = function(test, common) {
test ( 'address alias layer plus regular layers' , function ( t ) {
var address _layers = [ 'osmaddress' , 'openaddresses' ] ;
var reg _layers = [ 'geoname' , 'osmway' ] ;
sanitize ( { layers : 'address,geoname,osmway' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : 'address,geoname,osmway' , lat : 0 , lon : 0 } , function ( err , clean ) {
t . deepEqual ( clean . types . from _layers , reg _layers . concat ( address _layers ) , 'address + regular layers set' ) ;
t . end ( ) ;
} ) ;
} ) ;
test ( 'alias layer plus regular layers (no duplicates)' , function ( t ) {
var poi _layers = [ 'geoname' , 'osmnode' , 'osmway' ] ;
sanitize ( { layers : 'poi,geoname,osmnode' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : 'poi,geoname,osmnode' , lat : 0 , lon : 0 } , function ( err , clean ) {
t . deepEqual ( clean . types . from _layers , poi _layers , 'poi layers found (no duplicates)' ) ;
t . end ( ) ;
} ) ;
} ) ;
test ( 'multiple alias layers (no duplicates)' , function ( t ) {
var alias _layers = [ 'geoname' , 'osmnode' , 'osmway' , 'admin0' , 'admin1' , 'admin2' , 'neighborhood' , 'locality' , 'local_admin' ] ;
sanitize ( { layers : 'poi,admin' , input : 'test' , lat : 0 , lon : 0 } , function ( err , clean ) {
sanitize ( { layers : 'poi,admin' , lat : 0 , lon : 0 } , function ( err , clean ) {
t . deepEqual ( clean . types . from _layers , alias _layers , 'all layers found (no duplicates)' ) ;
t . end ( ) ;
} ) ;
@ -231,7 +231,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
} ;
module . exports . tests . sanitize _categories = function ( test , common ) {
var queryParams = { input : 'test' , lat : 0 , lon : 0 } ;
var queryParams = { lat : 0 , lon : 0 } ;
test ( 'unspecified' , function ( t ) {
queryParams . categories = undefined ;
sanitize ( queryParams , function ( err , clean ) {
@ -284,7 +284,7 @@ module.exports.tests.middleware_failure = function(test, common) {
module . exports . tests . middleware _success = function ( test , common ) {
test ( 'middleware success' , function ( t ) {
var req = { query : { input : 'test' , lat : 0 , lon : 0 } } ;
var req = { query : { lat : 0 , lon : 0 } } ;
var next = function ( message ) {
t . equal ( message , undefined , 'no error message set' ) ;
t . deepEqual ( req . clean , defaultClean ) ;