mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.0 KiB
62 lines
2.0 KiB
9 years ago
|
|
||
8 years ago
|
var nearby = require('../../../sanitizer/nearby');
|
||
9 years ago
|
var defaults = require('../../../query/reverse_defaults');
|
||
|
var sanitize = nearby.sanitize;
|
||
|
var middleware = nearby.middleware;
|
||
9 years ago
|
|
||
9 years ago
|
var defaultClean = { 'point.lat': 0,
|
||
9 years ago
|
'point.lon': 0,
|
||
|
'boundary.circle.lat': 0,
|
||
|
'boundary.circle.lon': 0,
|
||
|
'boundary.circle.radius': parseFloat(defaults['boundary:circle:radius']),
|
||
|
size: 10,
|
||
|
private: false
|
||
|
};
|
||
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.interface = function(test, common) {
|
||
|
test('sanitize interface', function(t) {
|
||
|
t.equal(typeof sanitize, 'function', 'sanitize is a function');
|
||
|
t.equal(sanitize.length, 2, 'sanitize interface');
|
||
|
t.end();
|
||
|
});
|
||
|
test('middleware interface', function(t) {
|
||
|
t.equal(typeof middleware, 'function', 'middleware is a function');
|
||
|
t.equal(middleware.length, 3, 'sanitizee has a valid middleware');
|
||
|
t.end();
|
||
|
});
|
||
|
};
|
||
|
|
||
8 years ago
|
module.exports.tests.sanitizers = function(test, common) {
|
||
|
test('check sanitizer list', function (t) {
|
||
9 years ago
|
var expected = ['quattroshapes_deprecation', 'singleScalarParameters', 'layers',
|
||
|
'sources', 'sources_and_layers', 'size', 'private', 'geo_reverse', 'boundary_country', 'categories'];
|
||
8 years ago
|
t.deepEqual(Object.keys(nearby.sanitizer_list), expected);
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.tests.middleware_success = function(test, common) {
|
||
|
test('middleware success', function(t) {
|
||
|
var req = { query: { 'point.lat': 0, 'point.lon': 0 }};
|
||
|
var next = function(){
|
||
|
t.deepEqual(req.errors, [], 'no error message set');
|
||
|
t.deepEqual(req.clean, defaultClean);
|
||
|
t.end();
|
||
|
};
|
||
|
middleware( req, undefined, next );
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.all = function (tape, common) {
|
||
|
|
||
|
function test(name, testFunction) {
|
||
9 years ago
|
return tape('SANTIZE /nearby ' + name, testFunction);
|
||
9 years ago
|
}
|
||
|
|
||
|
for( var testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|