Browse Source

renamed `sanitise` -> `sanitize`

pull/676/head
Stephen Hess 8 years ago
parent
commit
3763d0b503
  1. 28
      routes/v1.js
  2. 34
      sanitiser/autocomplete.js
  3. 28
      sanitiser/reverse.js
  4. 26
      sanitiser/search.js
  5. 0
      sanitizer/_boundary_country.js
  6. 0
      sanitizer/_categories.js
  7. 0
      sanitizer/_deprecate_quattroshapes.js
  8. 0
      sanitizer/_details.js
  9. 0
      sanitizer/_flag_bool.js
  10. 0
      sanitizer/_geo_autocomplete.js
  11. 2
      sanitizer/_geo_common.js
  12. 0
      sanitizer/_geo_reverse.js
  13. 0
      sanitizer/_geo_search.js
  14. 0
      sanitizer/_groups.js
  15. 0
      sanitizer/_ids.js
  16. 0
      sanitizer/_single_scalar_parameters.js
  17. 0
      sanitizer/_size.js
  18. 4
      sanitizer/_sources_and_layers.js
  19. 0
      sanitizer/_targets.js
  20. 0
      sanitizer/_text.js
  21. 0
      sanitizer/_text_addressit.js
  22. 0
      sanitizer/_tokenizer.js
  23. 34
      sanitizer/autocomplete.js
  24. 8
      sanitizer/nearby.js
  25. 10
      sanitizer/place.js
  26. 28
      sanitizer/reverse.js
  27. 0
      sanitizer/sanitizeAll.js
  28. 26
      sanitizer/search.js
  29. 4
      sanitizer/search_fallback.js
  30. 0
      sanitizer/wrap.js
  31. 48
      test/unit/run.js
  32. 2
      test/unit/sanitizer/_boundary_country.js
  33. 2
      test/unit/sanitizer/_categories.js
  34. 2
      test/unit/sanitizer/_deprecate_quattroshapes.js
  35. 2
      test/unit/sanitizer/_flag_bool.js
  36. 2
      test/unit/sanitizer/_geo_common.js
  37. 2
      test/unit/sanitizer/_geo_reverse.js
  38. 2
      test/unit/sanitizer/_groups.js
  39. 2
      test/unit/sanitizer/_ids.js
  40. 2
      test/unit/sanitizer/_layers.js
  41. 2
      test/unit/sanitizer/_single_scalar_parameters.js
  42. 2
      test/unit/sanitizer/_size.js
  43. 2
      test/unit/sanitizer/_sources.js
  44. 2
      test/unit/sanitizer/_sources_and_layers.js
  45. 22
      test/unit/sanitizer/_text.js
  46. 2
      test/unit/sanitizer/_text_addressit.js
  47. 40
      test/unit/sanitizer/_tokenizer.js
  48. 2
      test/unit/sanitizer/_truthy.js
  49. 8
      test/unit/sanitizer/autocomplete.js
  50. 8
      test/unit/sanitizer/nearby.js
  51. 8
      test/unit/sanitizer/place.js
  52. 8
      test/unit/sanitizer/reverse.js
  53. 2
      test/unit/sanitizer/sanitizeAll.js
  54. 52
      test/unit/sanitizer/search.js
  55. 64
      test/unit/sanitizer/search_fallback.js
  56. 2
      test/unit/sanitizer/wrap.js

28
routes/v1.js

@ -2,14 +2,14 @@ var express = require('express');
var Router = require('express').Router;
var reverseQuery = require('../query/reverse');
/** ----------------------- sanitisers ----------------------- **/
var sanitisers = {
autocomplete: require('../sanitiser/autocomplete'),
place: require('../sanitiser/place'),
search: require('../sanitiser/search'),
search_fallback: require('../sanitiser/search_fallback'),
reverse: require('../sanitiser/reverse'),
nearby: require('../sanitiser/nearby')
/** ----------------------- sanitizers ----------------------- **/
var sanitizers = {
autocomplete: require('../sanitizer/autocomplete'),
place: require('../sanitizer/place'),
search: require('../sanitizer/search'),
search_fallback: require('../sanitizer/search_fallback'),
reverse: require('../sanitizer/reverse'),
nearby: require('../sanitizer/nearby')
};
/** ----------------------- middleware ------------------------ **/
@ -69,13 +69,13 @@ function addRoutes(app, peliasConfig) {
controllers.mdToHTML(peliasConfig, './public/attribution.md')
]),
search: createRouter([
sanitisers.search.middleware,
sanitizers.search.middleware,
middleware.calcSize(),
// 2nd parameter is `backend` which gets initialized internally
// 3rd parameter is which query module to use, use fallback/geodisambiguation
// first, then use original search strategy if first query didn't return anything
controllers.search(peliasConfig, undefined, queries.libpostal),
sanitisers.search_fallback.middleware,
sanitizers.search_fallback.middleware,
controllers.search(peliasConfig, undefined, queries.fallback_to_old_prod),
postProc.trimByGranularity(),
postProc.distances('focus.point.'),
@ -91,7 +91,7 @@ function addRoutes(app, peliasConfig) {
postProc.sendJSON
]),
autocomplete: createRouter([
sanitisers.autocomplete.middleware,
sanitizers.autocomplete.middleware,
controllers.search(peliasConfig, null, require('../query/autocomplete')),
postProc.distances('focus.point.'),
postProc.confidenceScores(peliasConfig),
@ -105,7 +105,7 @@ function addRoutes(app, peliasConfig) {
postProc.sendJSON
]),
reverse: createRouter([
sanitisers.reverse.middleware,
sanitizers.reverse.middleware,
middleware.calcSize(),
controllers.search(peliasConfig, undefined, reverseQuery),
postProc.distances('point.'),
@ -122,7 +122,7 @@ function addRoutes(app, peliasConfig) {
postProc.sendJSON
]),
nearby: createRouter([
sanitisers.nearby.middleware,
sanitizers.nearby.middleware,
middleware.calcSize(),
controllers.search(peliasConfig, undefined, reverseQuery),
postProc.distances('point.'),
@ -139,7 +139,7 @@ function addRoutes(app, peliasConfig) {
postProc.sendJSON
]),
place: createRouter([
sanitisers.place.middleware,
sanitizers.place.middleware,
controllers.place(peliasConfig),
postProc.accuracy(),
postProc.localNamingConventions(),

34
sanitiser/autocomplete.js

@ -1,34 +0,0 @@
var type_mapping = require('../helper/type_mapping');
var sanitizeAll = require('../sanitiser/sanitizeAll'),
sanitizers = {
singleScalarParameters: require('../sanitiser/_single_scalar_parameters'),
text: require('../sanitiser/_text_addressit'),
tokenizer: require('../sanitiser/_tokenizer'),
size: require('../sanitiser/_size')(10, 10, 10),
layers: require('../sanitiser/_targets')('layers', type_mapping.layer_mapping),
sources: require('../sanitiser/_targets')('sources', type_mapping.source_mapping),
// depends on the layers and sources sanitisers, must be run after them
sources_and_layers: require('../sanitiser/_sources_and_layers'),
private: require('../sanitiser/_flag_bool')('private', false),
geo_autocomplete: require('../sanitiser/_geo_autocomplete'),
boundary_country: require('../sanitiser/_boundary_country'),
categories: require('../sanitiser/_categories')
};
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;
module.exports.sanitiser_list = sanitizers;
// middleware
module.exports.middleware = function( req, res, next ){
sanitize( req, function( err, clean ){
if( err ){
res.status(400); // 400 Bad Request
return next(err);
}
next();
});
};

28
sanitiser/reverse.js

@ -1,28 +0,0 @@
var type_mapping = require('../helper/type_mapping');
var sanitizeAll = require('../sanitiser/sanitizeAll'),
sanitizers = {
quattroshapes_deprecation: require('../sanitiser/_deprecate_quattroshapes'),
singleScalarParameters: require('../sanitiser/_single_scalar_parameters'),
layers: require('../sanitiser/_targets')('layers', type_mapping.layer_mapping),
sources: require('../sanitiser/_targets')('sources', type_mapping.source_mapping),
// depends on the layers and sources sanitisers, must be run after them
sources_and_layers: require('../sanitiser/_sources_and_layers'),
size: require('../sanitiser/_size')(/* use defaults*/),
private: require('../sanitiser/_flag_bool')('private', false),
geo_reverse: require('../sanitiser/_geo_reverse'),
boundary_country: require('../sanitiser/_boundary_country')
};
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;
module.exports.sanitiser_list = sanitizers;
// middleware
module.exports.middleware = function( req, res, next ){
sanitize( req, function( err, clean ){
next();
});
};

26
sanitiser/search.js

@ -1,26 +0,0 @@
var type_mapping = require('../helper/type_mapping');
var sanitizeAll = require('../sanitiser/sanitizeAll'),
sanitizers = {
quattroshapes_deprecation: require('../sanitiser/_deprecate_quattroshapes'),
singleScalarParameters: require('../sanitiser/_single_scalar_parameters'),
text: require('../sanitiser/_text'),
size: require('../sanitiser/_size')(/* use defaults*/),
layers: require('../sanitiser/_targets')('layers', type_mapping.layer_mapping),
sources: require('../sanitiser/_targets')('sources', type_mapping.source_mapping),
// depends on the layers and sources sanitisers, must be run after them
sources_and_layers: require('../sanitiser/_sources_and_layers'),
private: require('../sanitiser/_flag_bool')('private', false),
geo_search: require('../sanitiser/_geo_search'),
boundary_country: require('../sanitiser/_boundary_country'),
categories: require('../sanitiser/_categories')
};
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// middleware
module.exports.middleware = function( req, res, next ){
sanitize( req, function( err, clean ){
next();
});
};

0
sanitiser/_boundary_country.js → sanitizer/_boundary_country.js

0
sanitiser/_categories.js → sanitizer/_categories.js

0
sanitiser/_deprecate_quattroshapes.js → sanitizer/_deprecate_quattroshapes.js

0
sanitiser/_details.js → sanitizer/_details.js

0
sanitiser/_flag_bool.js → sanitizer/_flag_bool.js

0
sanitiser/_geo_autocomplete.js → sanitizer/_geo_autocomplete.js

2
sanitiser/_geo_common.js → sanitizer/_geo_common.js

@ -1,5 +1,5 @@
/**
* helper sanitiser methods for geo parameters
* helper sanitizer methods for geo parameters
*/
var groups = require('./_groups'),
util = require('util'),

0
sanitiser/_geo_reverse.js → sanitizer/_geo_reverse.js

0
sanitiser/_geo_search.js → sanitizer/_geo_search.js

0
sanitiser/_groups.js → sanitizer/_groups.js

0
sanitiser/_ids.js → sanitizer/_ids.js

0
sanitiser/_single_scalar_parameters.js → sanitizer/_single_scalar_parameters.js

0
sanitiser/_size.js → sanitizer/_size.js

4
sanitiser/_sources_and_layers.js → sanitizer/_sources_and_layers.js

@ -2,8 +2,8 @@ var _ = require( 'lodash' );
var type_mapping = require( '../helper/type_mapping' );
/*
* This sanitiser depends on clean.layers and clean.sources
* so it has to be run after those sanitisers have been run
* This sanitizer depends on clean.layers and clean.sources
* so it has to be run after those sanitizers have been run
*/
function sanitize( raw, clean ){
var messages = { errors: [], warnings: [] };

0
sanitiser/_targets.js → sanitizer/_targets.js

0
sanitiser/_text.js → sanitizer/_text.js

0
sanitiser/_text_addressit.js → sanitizer/_text_addressit.js

0
sanitiser/_tokenizer.js → sanitizer/_tokenizer.js

34
sanitizer/autocomplete.js

@ -0,0 +1,34 @@
var type_mapping = require('../helper/type_mapping');
var sanitizeAll = require('../sanitizer/sanitizeAll'),
sanitizers = {
singleScalarParameters: require('../sanitizer/_single_scalar_parameters'),
text: require('../sanitizer/_text_addressit'),
tokenizer: require('../sanitizer/_tokenizer'),
size: require('../sanitizer/_size')(10, 10, 10),
layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping),
sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping),
// depends on the layers and sources sanitizers, must be run after them
sources_and_layers: require('../sanitizer/_sources_and_layers'),
private: require('../sanitizer/_flag_bool')('private', false),
geo_autocomplete: require('../sanitizer/_geo_autocomplete'),
boundary_country: require('../sanitizer/_boundary_country'),
categories: require('../sanitizer/_categories')
};
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;
module.exports.sanitizer_list = sanitizers;
// middleware
module.exports.middleware = function( req, res, next ){
sanitize( req, function( err, clean ){
if( err ){
res.status(400); // 400 Bad Request
return next(err);
}
next();
});
};

8
sanitiser/nearby.js → sanitizer/nearby.js

@ -1,17 +1,17 @@
var _ = require('lodash');
var sanitizeAll = require('../sanitiser/sanitizeAll');
var reverseSanitizers = require('./reverse').sanitiser_list;
var sanitizeAll = require('../sanitizer/sanitizeAll');
var reverseSanitizers = require('./reverse').sanitizer_list;
// add categories to the sanitizer list
var sanitizers = _.merge({}, reverseSanitizers, {
categories: require('../sanitiser/_categories')
categories: require('../sanitizer/_categories')
});
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;
module.exports.sanitiser_list = sanitizers;
module.exports.sanitizer_list = sanitizers;
// middleware
module.exports.middleware = function( req, res, next ){

10
sanitiser/place.js → sanitizer/place.js

@ -1,16 +1,16 @@
var sanitizeAll = require('../sanitiser/sanitizeAll'),
var sanitizeAll = require('../sanitizer/sanitizeAll'),
sanitizers = {
singleScalarParameters: require('../sanitiser/_single_scalar_parameters'),
ids: require('../sanitiser/_ids'),
private: require('../sanitiser/_flag_bool')('private', false)
singleScalarParameters: require('../sanitizer/_single_scalar_parameters'),
ids: require('../sanitizer/_ids'),
private: require('../sanitizer/_flag_bool')('private', false)
};
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;
module.exports.sanitiser_list = sanitizers;
module.exports.sanitizer_list = sanitizers;
// middleware
module.exports.middleware = function( req, res, next ){

28
sanitizer/reverse.js

@ -0,0 +1,28 @@
var type_mapping = require('../helper/type_mapping');
var sanitizeAll = require('../sanitizer/sanitizeAll'),
sanitizers = {
quattroshapes_deprecation: require('../sanitizer/_deprecate_quattroshapes'),
singleScalarParameters: require('../sanitizer/_single_scalar_parameters'),
layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping),
sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping),
// depends on the layers and sources sanitizers, must be run after them
sources_and_layers: require('../sanitizer/_sources_and_layers'),
size: require('../sanitizer/_size')(/* use defaults*/),
private: require('../sanitizer/_flag_bool')('private', false),
geo_reverse: require('../sanitizer/_geo_reverse'),
boundary_country: require('../sanitizer/_boundary_country')
};
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;
module.exports.sanitizer_list = sanitizers;
// middleware
module.exports.middleware = function( req, res, next ){
sanitize( req, function( err, clean ){
next();
});
};

0
sanitiser/sanitizeAll.js → sanitizer/sanitizeAll.js

26
sanitizer/search.js

@ -0,0 +1,26 @@
var type_mapping = require('../helper/type_mapping');
var sanitizeAll = require('../sanitizer/sanitizeAll'),
sanitizers = {
quattroshapes_deprecation: require('../sanitizer/_deprecate_quattroshapes'),
singleScalarParameters: require('../sanitizer/_single_scalar_parameters'),
text: require('../sanitizer/_text'),
size: require('../sanitizer/_size')(/* use defaults*/),
layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping),
sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping),
// depends on the layers and sources sanitizers, must be run after them
sources_and_layers: require('../sanitizer/_sources_and_layers'),
private: require('../sanitizer/_flag_bool')('private', false),
geo_search: require('../sanitizer/_geo_search'),
boundary_country: require('../sanitizer/_boundary_country'),
categories: require('../sanitizer/_categories')
};
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };
// middleware
module.exports.middleware = function( req, res, next ){
sanitize( req, function( err, clean ){
next();
});
};

4
sanitiser/search_fallback.js → sanitizer/search_fallback.js

@ -1,6 +1,6 @@
var sanitizeAll = require('../sanitiser/sanitizeAll'),
var sanitizeAll = require('../sanitizer/sanitizeAll'),
sanitizers = {
text: require('../sanitiser/_text_addressit')
text: require('../sanitizer/_text_addressit')
};
var sanitize = function(req, cb) { sanitizeAll(req, sanitizers, cb); };

0
sanitiser/wrap.js → sanitizer/wrap.js

48
test/unit/run.js

@ -44,31 +44,31 @@ var tests = [
require('./query/search'),
require('./query/search_original'),
require('./query/text_parser'),
require('./sanitiser/_boundary_country'),
require('./sanitiser/_flag_bool'),
require('./sanitiser/_geo_common'),
require('./sanitiser/_geo_reverse'),
require('./sanitiser/_groups'),
require('./sanitiser/_ids'),
require('./sanitiser/_layers'),
require('./sanitiser/_single_scalar_parameters'),
require('./sanitiser/_size'),
require('./sanitiser/_sources'),
require('./sanitiser/_sources_and_layers'),
require('./sanitiser/_text'),
require('./sanitiser/_text_addressit'),
require('./sanitiser/_tokenizer'),
require('./sanitiser/_deprecate_quattroshapes'),
require('./sanitiser/_categories'),
require('./sanitiser/nearby'),
require('./sanitizer/_boundary_country'),
require('./sanitizer/_flag_bool'),
require('./sanitizer/_geo_common'),
require('./sanitizer/_geo_reverse'),
require('./sanitizer/_groups'),
require('./sanitizer/_ids'),
require('./sanitizer/_layers'),
require('./sanitizer/_single_scalar_parameters'),
require('./sanitizer/_size'),
require('./sanitizer/_sources'),
require('./sanitizer/_sources_and_layers'),
require('./sanitizer/_text'),
require('./sanitizer/_text_addressit'),
require('./sanitizer/_tokenizer'),
require('./sanitizer/_deprecate_quattroshapes'),
require('./sanitizer/_categories'),
require('./sanitizer/nearby'),
require('./src/backend'),
require('./sanitiser/autocomplete'),
require('./sanitiser/place'),
require('./sanitiser/reverse'),
require('./sanitiser/sanitizeAll'),
require('./sanitiser/search'),
require('./sanitiser/search_fallback'),
require('./sanitiser/wrap'),
require('./sanitizer/autocomplete'),
require('./sanitizer/place'),
require('./sanitizer/reverse'),
require('./sanitizer/sanitizeAll'),
require('./sanitizer/search'),
require('./sanitizer/search_fallback'),
require('./sanitizer/wrap'),
require('./service/mget'),
require('./service/search')
];

2
test/unit/sanitiser/_boundary_country.js → test/unit/sanitizer/_boundary_country.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_boundary_country');
var sanitize = require('../../../sanitizer/_boundary_country');
module.exports.tests = {};

2
test/unit/sanitiser/_categories.js → test/unit/sanitizer/_categories.js

@ -1,4 +1,4 @@
var sanitize = require( '../../../sanitiser/_categories');
var sanitize = require( '../../../sanitizer/_categories');
module.exports.tests = {};

2
test/unit/sanitiser/_deprecate_quattroshapes.js → test/unit/sanitizer/_deprecate_quattroshapes.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_deprecate_quattroshapes');
var sanitize = require('../../../sanitizer/_deprecate_quattroshapes');
module.exports.tests = {};

2
test/unit/sanitiser/_flag_bool.js → test/unit/sanitizer/_flag_bool.js

@ -1,4 +1,4 @@
var sanitizer = require('../../../sanitiser/_flag_bool');
var sanitizer = require('../../../sanitizer/_flag_bool');
var sanitize = sanitizer('dirty_param', true);
module.exports.tests = {};

2
test/unit/sanitiser/_geo_common.js → test/unit/sanitizer/_geo_common.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_geo_common');
var sanitize = require('../../../sanitizer/_geo_common');
module.exports.tests = {};

2
test/unit/sanitiser/_geo_reverse.js → test/unit/sanitizer/_geo_reverse.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_geo_reverse');
var sanitize = require('../../../sanitizer/_geo_reverse');
var defaults = require('../../../query/reverse_defaults');
module.exports.tests = {};

2
test/unit/sanitiser/_groups.js → test/unit/sanitizer/_groups.js

@ -1,4 +1,4 @@
var groups = require('../../../sanitiser/_groups');
var groups = require('../../../sanitizer/_groups');
module.exports.tests = {};

2
test/unit/sanitiser/_ids.js → test/unit/sanitizer/_ids.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_ids');
var sanitize = require('../../../sanitizer/_ids');
var delimiter = ':';
var type_mapping = require('../../../helper/type_mapping');

2
test/unit/sanitiser/_layers.js → test/unit/sanitizer/_layers.js

@ -1,6 +1,6 @@
var type_mapping = require('../../../helper/type_mapping');
var sanitize = require('../../../sanitiser/_targets')('layers', type_mapping.layer_mapping);
var sanitize = require('../../../sanitizer/_targets')('layers', type_mapping.layer_mapping);
module.exports.tests = {};

2
test/unit/sanitiser/_single_scalar_parameters.js → test/unit/sanitizer/_single_scalar_parameters.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_single_scalar_parameters');
var sanitize = require('../../../sanitizer/_single_scalar_parameters');
module.exports.tests = {};

2
test/unit/sanitiser/_size.js → test/unit/sanitizer/_size.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_size');
var sanitize = require('../../../sanitizer/_size');
module.exports.tests = {};

2
test/unit/sanitiser/_sources.js → test/unit/sanitizer/_sources.js

@ -1,5 +1,5 @@
var type_mapping = require('../../../helper/type_mapping');
var sanitize = require( '../../../sanitiser/_targets' )('sources', type_mapping.source_mapping);
var sanitize = require( '../../../sanitizer/_targets' )('sources', type_mapping.source_mapping);
var success_messages = { error: false };

2
test/unit/sanitiser/_sources_and_layers.js → test/unit/sanitizer/_sources_and_layers.js

@ -1,4 +1,4 @@
var sanitize = require('../../../sanitiser/_sources_and_layers');
var sanitize = require('../../../sanitizer/_sources_and_layers');
var type_mapping = require('../../../helper/type_mapping');

22
test/unit/sanitiser/_text.js → test/unit/sanitizer/_text.js

@ -10,7 +10,7 @@ module.exports.tests.text_parser = function(test, common) {
key2: 'value 2'
};
var sanitiser = proxyquire('../../../sanitiser/_text', {
var sanitizer = proxyquire('../../../sanitizer/_text', {
'pelias-text-analyzer': { parse: function(query) {
return mock_analyzer_response;
}
@ -27,7 +27,7 @@ module.exports.tests.text_parser = function(test, common) {
parsed_text: mock_analyzer_response
};
var messages = sanitiser(raw, clean);
var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, [], 'no errors');
@ -37,7 +37,7 @@ module.exports.tests.text_parser = function(test, common) {
});
test('empty raw.text should add error message', function(t) {
var sanitiser = proxyquire('../../../sanitiser/_text', {
var sanitizer = proxyquire('../../../sanitizer/_text', {
'pelias-text-analyzer': { parse: function(query) {
throw new Error('analyzer should not have been called');
}
@ -52,7 +52,7 @@ module.exports.tests.text_parser = function(test, common) {
var expected_clean = {
};
var messages = sanitiser(raw, clean);
var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, ['invalid param \'text\': text length, must be >0'], 'no errors');
@ -62,7 +62,7 @@ module.exports.tests.text_parser = function(test, common) {
});
test('undefined raw.text should add error message', function(t) {
var sanitiser = proxyquire('../../../sanitiser/_text', {
var sanitizer = proxyquire('../../../sanitizer/_text', {
'pelias-text-analyzer': { parse: function(query) {
throw new Error('analyzer should not have been called');
}
@ -77,7 +77,7 @@ module.exports.tests.text_parser = function(test, common) {
var expected_clean = {
};
var messages = sanitiser(raw, clean);
var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, ['invalid param \'text\': text length, must be >0'], 'no errors');
@ -87,7 +87,7 @@ module.exports.tests.text_parser = function(test, common) {
});
test('text_analyzer.parse returning undefined should not overwrite clean.parsed_text', function(t) {
var sanitiser = proxyquire('../../../sanitiser/_text', {
var sanitizer = proxyquire('../../../sanitizer/_text', {
'pelias-text-analyzer': { parse: function(query) {
return undefined;
}
@ -105,7 +105,7 @@ module.exports.tests.text_parser = function(test, common) {
parsed_text: 'original clean.parsed_text'
};
var messages = sanitiser(raw, clean);
var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, [], 'no errors');
@ -115,7 +115,7 @@ module.exports.tests.text_parser = function(test, common) {
});
test('text_analyzer.parse returning null should not overwrite clean.parsed_text', function(t) {
var sanitiser = proxyquire('../../../sanitiser/_text', {
var sanitizer = proxyquire('../../../sanitizer/_text', {
'pelias-text-analyzer': { parse: function(query) {
return null;
}
@ -133,7 +133,7 @@ module.exports.tests.text_parser = function(test, common) {
parsed_text: 'original clean.parsed_text'
};
var messages = sanitiser(raw, clean);
var messages = sanitizer(raw, clean);
t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, [], 'no errors');
@ -146,7 +146,7 @@ module.exports.tests.text_parser = function(test, common) {
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('SANITISER _text: ' + name, testFunction);
return tape('sanitizeR _text: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){

2
test/unit/sanitiser/_text_addressit.js → test/unit/sanitizer/_text_addressit.js

@ -1,4 +1,4 @@
var sanitiser = require('../../../sanitiser/_text_addressit');
var sanitiser = require('../../../sanitizer/_text_addressit');
var type_mapping = require('../../../helper/type_mapping');
module.exports.tests = {};

40
test/unit/sanitiser/_tokenizer.js → test/unit/sanitizer/_tokenizer.js

@ -1,4 +1,4 @@
var sanitiser = require('../../../sanitiser/_tokenizer');
var sanitizer = require('../../../sanitizer/_tokenizer');
module.exports.tests = {};
@ -6,7 +6,7 @@ module.exports.tests.sanity_checks = function(test, common) {
test('clean.text not set', function(t) {
var clean = {}; // clean.text not set
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// no tokens produced
t.deepEquals(clean.tokens, [], 'no tokens');
@ -22,7 +22,7 @@ module.exports.tests.sanity_checks = function(test, common) {
test('clean.text not a string', function(t) {
var clean = { text: {} }; // clean.text not a string
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// no tokens produced
t.deepEquals(clean.tokens, [], 'no tokens');
@ -38,7 +38,7 @@ module.exports.tests.sanity_checks = function(test, common) {
test('empty string', function(t) {
var clean = { text: '' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// no tokens produced
t.deepEquals(clean.tokens, [], 'no tokens');
@ -54,7 +54,7 @@ module.exports.tests.sanity_checks = function(test, common) {
test('clean.parsed_text set but clean.parsed_text.name invalid', function(t) {
var clean = { parsed_text: { text: {} } };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// no tokens produced
t.deepEquals(clean.tokens, [], 'no tokens');
@ -70,7 +70,7 @@ module.exports.tests.sanity_checks = function(test, common) {
test('favor clean.parsed_text.name over clean.text', function(t) {
var clean = { parsed_text: { name: 'foo' }, text: 'bar' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// favor clean.parsed_text.name over clean.text
t.deepEquals(clean.tokens, [ 'foo' ], 'use clean.parsed_text.name');
@ -86,7 +86,7 @@ module.exports.tests.sanity_checks = function(test, common) {
test('favor clean.parsed_text street data over clean.text', function(t) {
var clean = { parsed_text: { number: '190', street: 'foo st' }, text: 'bar' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// favor clean.parsed_text.name over clean.text
t.deepEquals(clean.tokens, [ '190', 'foo', 'st' ], 'use street name + number');
@ -102,7 +102,7 @@ module.exports.tests.sanity_checks = function(test, common) {
test('favor clean.parsed_text.name over clean.parsed_text street data', function(t) {
var clean = { parsed_text: { number: '190', street: 'foo st', name: 'foo' }, text: 'bar' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// favor clean.parsed_text.name over all other variables
t.deepEquals(clean.tokens, [ 'foo' ], 'use clean.parsed_text.name');
@ -121,7 +121,7 @@ module.exports.tests.space_delimiter = function(test, common) {
test('space delimiter - simple', function(t) {
var clean = { text: '30 west 26th street new york' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -156,7 +156,7 @@ module.exports.tests.space_delimiter = function(test, common) {
test('space delimiter - multiple spaces / other whitespace', function(t) {
var clean = { text: ' 30 west \t26th \nstreet new york ' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -194,7 +194,7 @@ module.exports.tests.comma_delimiter = function(test, common) {
test('comma delimiter - simple', function(t) {
var clean = { text: '30 west 26th street, new york' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -229,7 +229,7 @@ module.exports.tests.comma_delimiter = function(test, common) {
test('comma delimiter - multiple commas', function(t) {
var clean = { text: ',30 west 26th street,,, new york,' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -267,7 +267,7 @@ module.exports.tests.forward_slash_delimiter = function(test, common) {
test('forward slash delimiter - simple', function(t) {
var clean = { text: 'Bedell Street/133rd Avenue' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -298,7 +298,7 @@ module.exports.tests.forward_slash_delimiter = function(test, common) {
test('forward slash - multiple slashes', function(t) {
var clean = { text: '/Bedell Street//133rd Avenue/' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -332,7 +332,7 @@ module.exports.tests.final_token_single_gram = function(test, common) {
test('final token single gram - numeric', function(t) {
var clean = { text: 'grolmanstrasse 1' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -359,7 +359,7 @@ module.exports.tests.final_token_single_gram = function(test, common) {
test('final token single gram - non-numeric', function(t) {
var clean = { text: 'grolmanstrasse a' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -389,7 +389,7 @@ module.exports.tests.back_slash_delimiter = function(test, common) {
test('back slash delimiter - simple', function(t) {
var clean = { text: 'Bedell Street\\133rd Avenue' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -408,7 +408,7 @@ module.exports.tests.back_slash_delimiter = function(test, common) {
test('back slash - multiple slashes', function(t) {
var clean = { text: '\\Bedell Street\\\\133rd Avenue\\' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -430,7 +430,7 @@ module.exports.tests.mixed_delimiter = function(test, common) {
test('mixed delimiters', function(t) {
var clean = { text: ',/Bedell Street\\, \n\t ,\\//133rd Avenue, /\n/' };
var messages = sanitiser({}, clean);
var messages = sanitizer({}, clean);
// tokens produced
t.deepEquals(clean.tokens, [
@ -450,7 +450,7 @@ module.exports.tests.mixed_delimiter = function(test, common) {
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('SANITISER _tokenizer: ' + name, testFunction);
return tape('sanitizeR _tokenizer: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){

2
test/unit/sanitiser/_truthy.js → test/unit/sanitizer/_truthy.js

@ -1,4 +1,4 @@
var isTruthy = require('../../../sanitiser/_truthy');
var isTruthy = require('../../../sanitizer/_truthy');
module.exports.tests = {};

8
test/unit/sanitiser/autocomplete.js → test/unit/sanitizer/autocomplete.js

@ -1,14 +1,14 @@
var autocomplete = require('../../../sanitiser/autocomplete');
var autocomplete = require('../../../sanitizer/autocomplete');
module.exports.tests = {};
module.exports.tests.sanitisers = function(test, common) {
test('check sanitiser list', function (t) {
module.exports.tests.sanitizers = function(test, common) {
test('check sanitizer list', function (t) {
var expected = [
'singleScalarParameters', 'text', 'tokenizer', 'size', 'layers', 'sources',
'sources_and_layers', 'private', 'geo_autocomplete', 'boundary_country', 'categories'
];
t.deepEqual(Object.keys(autocomplete.sanitiser_list), expected);
t.deepEqual(Object.keys(autocomplete.sanitizer_list), expected);
t.end();
});
};

8
test/unit/sanitiser/nearby.js → test/unit/sanitizer/nearby.js

@ -1,5 +1,5 @@
var nearby = require('../../../sanitiser/nearby');
var nearby = require('../../../sanitizer/nearby');
var defaults = require('../../../query/reverse_defaults');
var sanitize = nearby.sanitize;
var middleware = nearby.middleware;
@ -28,11 +28,11 @@ module.exports.tests.interface = function(test, common) {
});
};
module.exports.tests.sanitisers = function(test, common) {
test('check sanitiser list', function (t) {
module.exports.tests.sanitizers = function(test, common) {
test('check sanitizer list', function (t) {
var expected = ['quattroshapes_deprecation', 'singleScalarParameters', 'layers',
'sources', 'sources_and_layers', 'size', 'private', 'geo_reverse', 'boundary_country', 'categories'];
t.deepEqual(Object.keys(nearby.sanitiser_list), expected);
t.deepEqual(Object.keys(nearby.sanitizer_list), expected);
t.end();
});
};

8
test/unit/sanitiser/place.js → test/unit/sanitizer/place.js

@ -1,4 +1,4 @@
var place = require('../../../sanitiser/place'),
var place = require('../../../sanitizer/place'),
sanitize = place.sanitize,
middleware = place.middleware,
defaultClean = { ids: [ { source: 'geonames', layer: 'venue', id: '123' } ], private: false };
@ -19,10 +19,10 @@ module.exports.tests.interface = function(test, common) {
});
};
module.exports.tests.sanitisers = function(test, common) {
test('check sanitiser list', function (t) {
module.exports.tests.sanitizers = function(test, common) {
test('check sanitizer list', function (t) {
var expected = ['singleScalarParameters', 'ids', 'private' ];
t.deepEqual(Object.keys(place.sanitiser_list), expected);
t.deepEqual(Object.keys(place.sanitizer_list), expected);
t.end();
});
};

8
test/unit/sanitiser/reverse.js → test/unit/sanitizer/reverse.js

@ -1,7 +1,7 @@
// @todo: refactor this test, it's pretty messy, brittle and hard to follow
var reverse = require('../../../sanitiser/reverse'),
var reverse = require('../../../sanitizer/reverse'),
sanitize = reverse.sanitize,
middleware = reverse.middleware,
defaults = require('../../../query/reverse_defaults'),
@ -34,11 +34,11 @@ module.exports.tests.interface = function(test, common) {
});
};
module.exports.tests.sanitisers = function(test, common) {
test('check sanitiser list', function (t) {
module.exports.tests.sanitizers = function(test, common) {
test('check sanitizer list', function (t) {
var expected = ['quattroshapes_deprecation', 'singleScalarParameters', 'layers',
'sources', 'sources_and_layers', 'size', 'private', 'geo_reverse', 'boundary_country'];
t.deepEqual(Object.keys(reverse.sanitiser_list), expected);
t.deepEqual(Object.keys(reverse.sanitizer_list), expected);
t.end();
});
};

2
test/unit/sanitiser/sanitizeAll.js → test/unit/sanitizer/sanitizeAll.js

@ -1,4 +1,4 @@
var sanitizeAll = require('../../../sanitiser/sanitizeAll');
var sanitizeAll = require('../../../sanitizer/sanitizeAll');
module.exports.tests = {};

52
test/unit/sanitiser/search.js → test/unit/sanitizer/search.js

@ -3,28 +3,28 @@ 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 = [];
test('verify that all sanitizers were called as expected', function(t) {
var called_sanitizers = [];
// rather than re-verify the functionality of all the sanitisers, 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
var search = proxyquire('../../../sanitiser/search', {
'../sanitiser/_deprecate_quattroshapes': function() {
called_sanitisers.push('_deprecate_quattroshapes');
var search = proxyquire('../../../sanitizer/search', {
'../sanitizer/_deprecate_quattroshapes': function() {
called_sanitizers.push('_deprecate_quattroshapes');
return { errors: [], warnings: [] };
},
'../sanitiser/_single_scalar_parameters': function() {
called_sanitisers.push('_single_scalar_parameters');
'../sanitizer/_single_scalar_parameters': function() {
called_sanitizers.push('_single_scalar_parameters');
return { errors: [], warnings: [] };
},
'../sanitiser/_text': function() {
called_sanitisers.push('_text');
'../sanitizer/_text': function() {
called_sanitizers.push('_text');
return { errors: [], warnings: [] };
},
'../sanitiser/_size': function() {
'../sanitizer/_size': function() {
if (arguments.length === 0) {
return function() {
called_sanitisers.push('_size');
called_sanitizers.push('_size');
return { errors: [], warnings: [] };
};
@ -33,10 +33,10 @@ module.exports.tests.sanitize = function(test, common) {
}
},
'../sanitiser/_targets': function(type) {
'../sanitizer/_targets': function(type) {
if (['layers', 'sources'].indexOf(type) !== -1) {
return function() {
called_sanitisers.push('_targets/' + type);
called_sanitizers.push('_targets/' + type);
return { errors: [], warnings: [] };
};
@ -46,14 +46,14 @@ module.exports.tests.sanitize = function(test, common) {
}
},
'../sanitiser/_sources_and_layers': function() {
called_sanitisers.push('_sources_and_layers');
'../sanitizer/_sources_and_layers': function() {
called_sanitizers.push('_sources_and_layers');
return { errors: [], warnings: [] };
},
'../sanitiser/_flag_bool': function() {
'../sanitizer/_flag_bool': function() {
if (arguments[0] === 'private' && arguments[1] === false) {
return function() {
called_sanitisers.push('_flag_bool');
called_sanitizers.push('_flag_bool');
return { errors: [], warnings: [] };
};
@ -63,21 +63,21 @@ module.exports.tests.sanitize = function(test, common) {
}
},
'../sanitiser/_geo_search': function() {
called_sanitisers.push('_geo_search');
'../sanitizer/_geo_search': function() {
called_sanitizers.push('_geo_search');
return { errors: [], warnings: [] };
},
'../sanitiser/_boundary_country': function() {
called_sanitisers.push('_boundary_country');
'../sanitizer/_boundary_country': function() {
called_sanitizers.push('_boundary_country');
return { errors: [], warnings: [] };
},
'../sanitiser/_categories': function() {
called_sanitisers.push('_categories');
'../sanitizer/_categories': function() {
called_sanitizers.push('_categories');
return { errors: [], warnings: [] };
},
});
var expected_sanitisers = [
var expected_sanitizers = [
'_deprecate_quattroshapes',
'_single_scalar_parameters',
'_text',
@ -95,7 +95,7 @@ module.exports.tests.sanitize = function(test, common) {
var res = {};
search.middleware(req, res, function(){
t.deepEquals(called_sanitisers, expected_sanitisers);
t.deepEquals(called_sanitizers, expected_sanitizers);
t.end();
});
});

64
test/unit/sanitiser/search_fallback.js → test/unit/sanitizer/search_fallback.js

@ -3,44 +3,44 @@ var proxyquire = require('proxyquire').noCallThru();
module.exports.tests = {};
module.exports.tests.sanitize = function(test, common) {
test('verify that all sanitisers were called as expected when `res` is undefined', function(t) {
var called_sanitisers = [];
test('verify that all sanitizers were called as expected when `res` is undefined', function(t) {
var called_sanitizers = [];
// rather than re-verify the functionality of all the sanitisers, 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
var search = proxyquire('../../../sanitiser/search_fallback', {
'../sanitiser/_text_addressit': function() {
called_sanitisers.push('_text_addressit');
var search = proxyquire('../../../sanitizer/search_fallback', {
'../sanitizer/_text_addressit': function() {
called_sanitizers.push('_text_addressit');
return { errors: [], warnings: [] };
}
});
var expected_sanitisers = [
var expected_sanitizers = [
'_text_addressit'
];
var req = {};
search.middleware(req, undefined, function(){
t.deepEquals(called_sanitisers, expected_sanitisers);
t.deepEquals(called_sanitizers, expected_sanitizers);
t.end();
});
});
test('verify that all sanitisers were called as expected when `res` has no `data` property', function(t) {
var called_sanitisers = [];
test('verify that all sanitizers were called as expected when `res` has no `data` property', function(t) {
var called_sanitizers = [];
// rather than re-verify the functionality of all the sanitisers, 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
var search = proxyquire('../../../sanitiser/search_fallback', {
'../sanitiser/_text_addressit': function() {
called_sanitisers.push('_text_addressit');
var search = proxyquire('../../../sanitizer/search_fallback', {
'../sanitizer/_text_addressit': function() {
called_sanitizers.push('_text_addressit');
return { errors: [], warnings: [] };
}
});
var expected_sanitisers = [
var expected_sanitizers = [
'_text_addressit'
];
@ -48,25 +48,25 @@ module.exports.tests.sanitize = function(test, common) {
var res = {};
search.middleware(req, res, function(){
t.deepEquals(called_sanitisers, expected_sanitisers);
t.deepEquals(called_sanitizers, expected_sanitizers);
t.end();
});
});
test('verify that all sanitisers were called as expected when res.data is empty', function(t) {
var called_sanitisers = [];
test('verify that all sanitizers were called as expected when res.data is empty', function(t) {
var called_sanitizers = [];
// rather than re-verify the functionality of all the sanitisers, 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
var search = proxyquire('../../../sanitiser/search_fallback', {
'../sanitiser/_text_addressit': function() {
called_sanitisers.push('_text_addressit');
var search = proxyquire('../../../sanitizer/search_fallback', {
'../sanitizer/_text_addressit': function() {
called_sanitizers.push('_text_addressit');
return { errors: [], warnings: [] };
}
});
var expected_sanitisers = [
var expected_sanitizers = [
'_text_addressit'
];
@ -76,24 +76,24 @@ module.exports.tests.sanitize = function(test, common) {
};
search.middleware(req, res, function(){
t.deepEquals(called_sanitisers, expected_sanitisers);
t.deepEquals(called_sanitizers, expected_sanitizers);
t.end();
});
});
test('non-empty res.data should not call the _text_autocomplete sanitiser', function(t) {
var called_sanitisers = [];
test('non-empty res.data should not call the _text_autocomplete sanitizer', function(t) {
var called_sanitizers = [];
// rather than re-verify the functionality of all the sanitisers, 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
var search = proxyquire('../../../sanitiser/search_fallback', {
'../sanitiser/_text_autocomplete': function() {
throw new Error('_text_autocomplete sanitiser should not have been called');
var search = proxyquire('../../../sanitizer/search_fallback', {
'../sanitizer/_text_autocomplete': function() {
throw new Error('_text_autocomplete sanitizer should not have been called');
}
});
var expected_sanitisers = [];
var expected_sanitizers = [];
var req = {};
var res = {
@ -101,7 +101,7 @@ module.exports.tests.sanitize = function(test, common) {
};
search.middleware(req, res, function(){
t.deepEquals(called_sanitisers, expected_sanitisers);
t.deepEquals(called_sanitizers, expected_sanitizers);
t.end();
});

2
test/unit/sanitiser/wrap.js → test/unit/sanitizer/wrap.js

@ -1,5 +1,5 @@
var wrap = require('../../../sanitiser/wrap');
var wrap = require('../../../sanitizer/wrap');
module.exports.tests = {};
Loading…
Cancel
Save