mirror of https://github.com/pelias/api.git
Stephen Hess
9 years ago
2 changed files with 54 additions and 0 deletions
@ -0,0 +1,13 @@ |
|||||||
|
var sanitizeAll = require('../sanitiser/sanitizeAll'), |
||||||
|
sanitizers = { |
||||||
|
text: require('../sanitiser/_text_autocomplete') |
||||||
|
}; |
||||||
|
|
||||||
|
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); }; |
||||||
|
|
||||||
|
// middleware
|
||||||
|
module.exports.middleware = function( req, res, next ){ |
||||||
|
sanitize( req, function( err, clean ){ |
||||||
|
next(); |
||||||
|
}); |
||||||
|
}; |
@ -0,0 +1,41 @@ |
|||||||
|
var proxyquire = require('proxyquire').noCallThru(); |
||||||
|
|
||||||
|
module.exports.tests = {}; |
||||||
|
|
||||||
|
module.exports.tests.sanitize = function(test, common) { |
||||||
|
test('verify that all sanitisers were called as expected', function(t) { |
||||||
|
var called_sanitisers = []; |
||||||
|
|
||||||
|
// rather than re-verify the functionality of all the sanitisers, this test just verifies that they
|
||||||
|
// were all called correctly
|
||||||
|
var search = proxyquire('../../../sanitiser/search_fallback', { |
||||||
|
'../sanitiser/_text_autocomplete': function() { |
||||||
|
called_sanitisers.push('_text_autocomplete'); |
||||||
|
return { errors: [], warnings: [] }; |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
var expected_sanitisers = [ |
||||||
|
'_text_autocomplete' |
||||||
|
]; |
||||||
|
|
||||||
|
var req = {}; |
||||||
|
var res = {}; |
||||||
|
|
||||||
|
search.middleware(req, res, function(){ |
||||||
|
t.deepEquals(called_sanitisers, expected_sanitisers); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
}; |
Loading…
Reference in new issue