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.
114 lines
3.3 KiB
114 lines
3.3 KiB
8 years ago
|
var proxyquire = require('proxyquire').noCallThru();
|
||
10 years ago
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
8 years ago
|
module.exports.tests.sanitize = function(test, common) {
|
||
8 years ago
|
test('verify that all sanitizers were called as expected', function(t) {
|
||
|
var called_sanitizers = [];
|
||
8 years ago
|
|
||
8 years ago
|
// rather than re-verify the functionality of all the sanitizers, this test just verifies that they
|
||
8 years ago
|
// were all called correctly
|
||
8 years ago
|
var search = proxyquire('../../../sanitizer/search', {
|
||
|
'../sanitizer/_deprecate_quattroshapes': function() {
|
||
|
called_sanitizers.push('_deprecate_quattroshapes');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_single_scalar_parameters': function() {
|
||
|
called_sanitizers.push('_single_scalar_parameters');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_text': function() {
|
||
|
called_sanitizers.push('_text');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_size': function() {
|
||
8 years ago
|
if (arguments.length === 0) {
|
||
|
return function() {
|
||
8 years ago
|
called_sanitizers.push('_size');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
};
|
||
|
|
||
|
} else {
|
||
|
throw new Error('should not have passed any parameters to _size');
|
||
|
}
|
||
|
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_targets': function(type) {
|
||
8 years ago
|
if (['layers', 'sources'].indexOf(type) !== -1) {
|
||
|
return function() {
|
||
8 years ago
|
called_sanitizers.push('_targets/' + type);
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
};
|
||
|
|
||
|
}
|
||
|
else {
|
||
|
throw new Error('incorrect parameters passed to _targets');
|
||
|
}
|
||
|
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_sources_and_layers': function() {
|
||
|
called_sanitizers.push('_sources_and_layers');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_flag_bool': function() {
|
||
8 years ago
|
if (arguments[0] === 'private' && arguments[1] === false) {
|
||
|
return function() {
|
||
8 years ago
|
called_sanitizers.push('_flag_bool');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
};
|
||
|
|
||
|
}
|
||
|
else {
|
||
|
throw new Error('incorrect parameters passed to _flag_bool');
|
||
|
}
|
||
|
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_geo_search': function() {
|
||
|
called_sanitizers.push('_geo_search');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_boundary_country': function() {
|
||
|
called_sanitizers.push('_boundary_country');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_categories': function() {
|
||
|
called_sanitizers.push('_categories');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
|
});
|
||
|
|
||
8 years ago
|
var expected_sanitizers = [
|
||
8 years ago
|
'_deprecate_quattroshapes',
|
||
|
'_single_scalar_parameters',
|
||
|
'_text',
|
||
|
'_size',
|
||
|
'_targets/layers',
|
||
|
'_targets/sources',
|
||
|
'_sources_and_layers',
|
||
|
'_flag_bool',
|
||
|
'_geo_search',
|
||
|
'_boundary_country',
|
||
|
'_categories'
|
||
|
];
|
||
|
|
||
|
var req = {};
|
||
|
var res = {};
|
||
|
|
||
|
search.middleware(req, res, function(){
|
||
8 years ago
|
t.deepEquals(called_sanitizers, expected_sanitizers);
|
||
9 years ago
|
t.end();
|
||
10 years ago
|
});
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.all = function (tape, common) {
|
||
|
|
||
|
function test(name, testFunction) {
|
||
|
return tape('SANTIZE /search ' + name, testFunction);
|
||
|
}
|
||
|
|
||
|
for( var testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
10 years ago
|
};
|