Browse Source

adapt defer_to_addressit to new sanitizer format

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

6
sanitizer/defer_to_addressit.js

@ -1,9 +1,8 @@
const sanitizeAll = require('../sanitizer/sanitizeAll'),
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 logging = require( '../helper/logging' );
@ -23,9 +22,8 @@ module.exports = (should_execute) => {
logger.info(`fallback queryText: ${queryText}`);
}
sanitize( req, function( err, clean ){
sanitizeAll.sanitize(req, sanitizers);
next();
});
};

24
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
// were all called correctly
const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', {
'../sanitizer/_text_addressit': () => {
'../sanitizer/_text_addressit': function () {
return {
sanitize: () => {
t.fail('_text_addressit should not have been called');
}
};
},
'pelias-logger': logger
})(() => 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
// were all called correctly
const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', {
'../sanitizer/_text_addressit': () => {
'../sanitizer/_text_addressit': function () {
return {
sanitize: () => {
t.pass('_text_addressit should have been called');
return { errors: [], warnings: [] };
}
};
},
'pelias-logger': logger,
'../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
// were all called correctly
const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', {
'../sanitizer/_text_addressit': () => {
'../sanitizer/_text_addressit': function () {
return {
sanitize: () => {
t.pass('_text_addressit should have been called');
return { errors: [], warnings: [] };
}
};
},
'pelias-logger': logger
})(() => 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
// were all called correctly
const defer_to_addressit = proxyquire('../../../sanitizer/defer_to_addressit', {
'../sanitizer/_text_addressit': () => {
'../sanitizer/_text_addressit': function () {
return {
sanitize: () => {
t.pass('_text_addressit should have been called');
return { errors: [], warnings: [] };
}
};
},
'pelias-logger': logger,
'../helper/logging': {

Loading…
Cancel
Save