From 9a88d5a28b481618bb4add7393d85edb58a9a6b0 Mon Sep 17 00:00:00 2001 From: Lily He Date: Tue, 1 Aug 2017 17:01:48 -0400 Subject: [PATCH] unmerge nearby sanitizers from reverse sanitizer_list --- sanitizer/nearby.js | 18 +++++-- test/unit/sanitizer/nearby.js | 94 +++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 4 deletions(-) diff --git a/sanitizer/nearby.js b/sanitizer/nearby.js index 00efefc4..021efa77 100644 --- a/sanitizer/nearby.js +++ b/sanitizer/nearby.js @@ -1,11 +1,21 @@ -var _ = require('lodash'); var sanitizeAll = require('../sanitizer/sanitizeAll'); -var reverseSanitizers = require('./reverse').sanitizer_list; +var type_mapping = require('../helper/type_mapping'); // add categories to the sanitizer list -var sanitizers = _.merge({}, reverseSanitizers, { +var sanitizers = { + singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(), + quattroshapes_deprecation: require('../sanitizer/_deprecate_quattroshapes')(), + 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')(), + geonames_deprecation: require('../sanitizer/_geonames_deprecation')(), + 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')(), categories: require('../sanitizer/_categories')() -}); +}; var sanitize = sanitizeAll.runAllChecks; diff --git a/test/unit/sanitizer/nearby.js b/test/unit/sanitizer/nearby.js index f691d4b8..d2d11f1f 100644 --- a/test/unit/sanitizer/nearby.js +++ b/test/unit/sanitizer/nearby.js @@ -10,6 +10,90 @@ module.exports.tests.sanitize = function(test, common) { // rather than re-verify the functionality of all the sanitizers, this test just verifies that they // were all called correctly var nearby = proxyquire('../../../sanitizer/nearby.js', { + '../sanitizer/_single_scalar_parameters': function () { + return { + sanitize: () => { + called_sanitizers.push('_single_scalar_parameters'); + return { errors: [], warnings: [] }; + } + }; + }, + '../sanitizer/_deprecate_quattroshapes': function () { + return { + sanitize: () => { + called_sanitizers.push('_deprecate_quattroshapes'); + return { errors: [], warnings: [] }; + } + }; + }, + '../sanitizer/_targets': function (type) { + if (['layers', 'sources'].indexOf(type) !== -1) { + return { + sanitize: () => { + called_sanitizers.push(`_targets/${type}`); + return { errors: [], warnings: [] }; + } + }; + } else { + throw new Error('incorrect parameters passed to _targets'); + } + }, + '../sanitizer/_sources_and_layers': function () { + return { + sanitize: () => { + called_sanitizers.push('_sources_and_layers'); + return { errors: [], warnings: [] }; + } + }; + }, + '../sanitizer/_geonames_deprecation': function () { + return { + sanitize: () => { + called_sanitizers.push('_geonames_deprecations'); + return { errors: [], warnings: [] }; + } + }; + }, + '../sanitizer/_size': function () { + if (_.isEmpty(arguments)) { + return { + sanitize: () => { + called_sanitizers.push('_size'); + return { errors: [], warnings: [] }; + } + }; + } else { + throw new Error('should not have passed any parameters to _size'); + } + }, + '../sanitizer/_flag_bool': function () { + if (arguments[0] === 'private' && arguments[1] === false) { + return { + sanitize: () => { + called_sanitizers.push('_flag_bool'); + return { errors: [], warnings: [] }; + } + }; + } else { + throw new Error('incorrect parameters passed to _flag_bool'); + } + }, + '../sanitizer/_geo_reverse': function () { + return { + sanitize: () => { + called_sanitizers.push('_geo_reverse'); + return { errors: [], warnings: [] }; + } + }; + }, + '../sanitizer/_boundary_country': function () { + return { + sanitize: () => { + called_sanitizers.push('_boundary_country'); + return { errors: [], warnings: [] }; + } + }; + }, '../sanitizer/_categories': function () { return { sanitize: () => { @@ -21,6 +105,16 @@ module.exports.tests.sanitize = function(test, common) { }); const expected_sanitizers = [ + '_single_scalar_parameters', + '_deprecate_quattroshapes', + '_targets/layers', + '_targets/sources', + '_sources_and_layers', + '_geonames_deprecations', + '_size', + '_flag_bool', + '_geo_reverse', + '_boundary_country', '_categories' ];