Browse Source

adapt defer_to_addressit to new sanitizer format

pull/942/head
Lily He 8 years ago
parent
commit
8e45af1e49
  1. 8
      sanitizer/defer_to_addressit.js
  2. 38
      test/unit/sanitizer/defer_to_addressit.js

8
sanitizer/defer_to_addressit.js

@ -1,9 +1,8 @@
const sanitizeAll = require('../sanitizer/sanitizeAll'), const sanitizeAll = require('../sanitizer/sanitizeAll'),
sanitizers = { sanitizers = {
text: require('../sanitizer/_text_addressit') text: require('../sanitizer/_text_addressit')()
}; };
const sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
const logger = require('pelias-logger').get('api'); const logger = require('pelias-logger').get('api');
const logging = require( '../helper/logging' ); const logging = require( '../helper/logging' );
@ -23,9 +22,8 @@ module.exports = (should_execute) => {
logger.info(`fallback queryText: ${queryText}`); logger.info(`fallback queryText: ${queryText}`);
} }
sanitize( req, function( err, clean ){ sanitizeAll.sanitize(req, sanitizers);
next(); next();
});
}; };

38
test/unit/sanitizer/defer_to_addressit.js

@ -12,8 +12,12 @@ module.exports.tests.sanitize = (test, common) => {
// rather than re-verify the functionality of all the sanitizers, this test just verifies that they // rather than re-verify the functionality of all the sanitizers, this test just verifies that they
// were all called correctly // were all called correctly
const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', { const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', {
'../sanitizer/_text_addressit': () => { '../sanitizer/_text_addressit': function () {
t.fail('_text_addressit should not have been called'); return {
sanitize: () => {
t.fail('_text_addressit should not have been called');
}
};
}, },
'pelias-logger': logger 'pelias-logger': logger
})(() => false); })(() => false);
@ -33,9 +37,13 @@ module.exports.tests.sanitize = (test, common) => {
// rather than re-verify the functionality of all the sanitizers, this test just verifies that they // rather than re-verify the functionality of all the sanitizers, this test just verifies that they
// were all called correctly // were all called correctly
const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', { const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', {
'../sanitizer/_text_addressit': () => { '../sanitizer/_text_addressit': function () {
t.pass('_text_addressit should have been called'); return {
return { errors: [], warnings: [] }; sanitize: () => {
t.pass('_text_addressit should have been called');
return { errors: [], warnings: [] };
}
};
}, },
'pelias-logger': logger, 'pelias-logger': logger,
'../helper/logging': { '../helper/logging': {
@ -65,9 +73,13 @@ module.exports.tests.sanitize = (test, common) => {
// rather than re-verify the functionality of all the sanitizers, this test just verifies that they // rather than re-verify the functionality of all the sanitizers, this test just verifies that they
// were all called correctly // were all called correctly
const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', { const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', {
'../sanitizer/_text_addressit': () => { '../sanitizer/_text_addressit': function () {
t.pass('_text_addressit should have been called'); return {
return { errors: [], warnings: [] }; sanitize: () => {
t.pass('_text_addressit should have been called');
return { errors: [], warnings: [] };
}
};
}, },
'pelias-logger': logger 'pelias-logger': logger
})(() => true); })(() => true);
@ -94,9 +106,13 @@ module.exports.tests.sanitize = (test, common) => {
// rather than re-verify the functionality of all the sanitizers, this test just verifies that they // rather than re-verify the functionality of all the sanitizers, this test just verifies that they
// were all called correctly // were all called correctly
const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', { const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', {
'../sanitizer/_text_addressit': () => { '../sanitizer/_text_addressit': function () {
t.pass('_text_addressit should have been called'); return {
return { errors: [], warnings: [] }; sanitize: () => {
t.pass('_text_addressit should have been called');
return { errors: [], warnings: [] };
}
};
}, },
'pelias-logger': logger, 'pelias-logger': logger,
'../helper/logging': { '../helper/logging': {

Loading…
Cancel
Save