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.
122 lines
3.3 KiB
122 lines
3.3 KiB
8 years ago
|
var proxyquire = require('proxyquire').noCallThru();
|
||
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.sanitize = function(test, common) {
|
||
8 years ago
|
test('verify that all sanitizers were called as expected when `res` is undefined', 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_fallback', {
|
||
|
'../sanitizer/_text_addressit': function() {
|
||
|
called_sanitizers.push('_text_addressit');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
}
|
||
|
});
|
||
|
|
||
8 years ago
|
var expected_sanitizers = [
|
||
8 years ago
|
'_text_addressit'
|
||
8 years ago
|
];
|
||
|
|
||
|
var req = {};
|
||
|
|
||
|
search.middleware(req, undefined, function(){
|
||
8 years ago
|
t.deepEquals(called_sanitizers, expected_sanitizers);
|
||
8 years ago
|
t.end();
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
8 years ago
|
test('verify that all sanitizers were called as expected when `res` has no `data` property', 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_fallback', {
|
||
|
'../sanitizer/_text_addressit': function() {
|
||
|
called_sanitizers.push('_text_addressit');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
}
|
||
|
});
|
||
|
|
||
8 years ago
|
var expected_sanitizers = [
|
||
8 years ago
|
'_text_addressit'
|
||
8 years ago
|
];
|
||
|
|
||
|
var req = {};
|
||
|
var res = {};
|
||
|
|
||
|
search.middleware(req, res, function(){
|
||
8 years ago
|
t.deepEquals(called_sanitizers, expected_sanitizers);
|
||
8 years ago
|
t.end();
|
||
|
});
|
||
8 years ago
|
|
||
|
});
|
||
|
|
||
8 years ago
|
test('verify that all sanitizers were called as expected when res.data is empty', 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_fallback', {
|
||
|
'../sanitizer/_text_addressit': function() {
|
||
|
called_sanitizers.push('_text_addressit');
|
||
8 years ago
|
return { errors: [], warnings: [] };
|
||
|
}
|
||
|
});
|
||
|
|
||
8 years ago
|
var expected_sanitizers = [
|
||
8 years ago
|
'_text_addressit'
|
||
8 years ago
|
];
|
||
|
|
||
|
var req = {};
|
||
|
var res = {
|
||
|
data: []
|
||
|
};
|
||
|
|
||
|
search.middleware(req, res, function(){
|
||
8 years ago
|
t.deepEquals(called_sanitizers, expected_sanitizers);
|
||
8 years ago
|
t.end();
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
8 years ago
|
test('non-empty res.data should not call the _text_autocomplete sanitizer', 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_fallback', {
|
||
|
'../sanitizer/_text_autocomplete': function() {
|
||
|
throw new Error('_text_autocomplete sanitizer should not have been called');
|
||
8 years ago
|
}
|
||
|
});
|
||
|
|
||
8 years ago
|
var expected_sanitizers = [];
|
||
8 years ago
|
|
||
|
var req = {};
|
||
|
var res = {
|
||
|
data: [{}]
|
||
|
};
|
||
|
|
||
|
search.middleware(req, res, function(){
|
||
8 years ago
|
t.deepEquals(called_sanitizers, expected_sanitizers);
|
||
8 years ago
|
t.end();
|
||
|
});
|
||
|
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
8 years ago
|
};
|
||
|
|
||
|
module.exports.all = function (tape, common) {
|
||
|
|
||
|
function test(name, testFunction) {
|
||
|
return tape('SANITIZE /search_fallback ' + name, testFunction);
|
||
|
}
|
||
|
|
||
|
for( var testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|