diff --git a/query/autocomplete.js b/query/autocomplete.js index 6e980a75c..eb8e79fe6 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -17,7 +17,8 @@ var views = { phrase_first_tokens_only: require('./view/phrase_first_tokens_only'), boost_exact_matches: require('./view/boost_exact_matches'), max_character_count_layer_filter: require('./view/max_character_count_layer_filter'), - focus_point_filter: require('./view/focus_point_distance_filter') + focus_point_filter: require('./view/focus_point_distance_filter'), + focus_multi_match: require('./view/focus_multi_match') }; // add abbrevations for the fields pelias/parser is able to detect. @@ -52,6 +53,8 @@ query.score( views.admin_multi_match_last( adminFields ), 'must'); query.score( peliasQuery.view.focus( peliasQuery.view.leaf.match_all ) ); query.score( peliasQuery.view.popularity( peliasQuery.view.leaf.match_all ) ); query.score( peliasQuery.view.population( peliasQuery.view.leaf.match_all ) ); +query.score( views.focus_multi_match('focus_country') ); +query.score( views.focus_multi_match('focus_gid') ); query.score( views.custom_boosts( config.get('api.customBoosts') ) ); // non-scoring hard filters @@ -92,6 +95,20 @@ function generateQuery( clean ){ }); } + // focus country + if( _.isArray(clean['focus.country']) && !_.isEmpty(clean['focus.country']) ){ + vs.set({ + 'multi_match:focus_country:input': clean['focus.country'].join(' ') + }); + } + + // focus gid + if( _.isString(clean['focus.gid']) && !_.isEmpty(clean['focus.gid']) ){ + vs.set({ + 'multi_match:focus_gid:input': clean['focus.gid'] + }); + } + // pass the input tokens to the views so they can choose which tokens // are relevant for their specific function. if( _.isArray( clean.tokens ) ){ diff --git a/query/autocomplete_defaults.js b/query/autocomplete_defaults.js index ca8eca7d7..7df8b8ddc 100644 --- a/query/autocomplete_defaults.js +++ b/query/autocomplete_defaults.js @@ -76,6 +76,16 @@ module.exports = _.merge({}, peliasQuery.defaults, { 'multi_match:boundary_country:analyzer': 'standard', 'multi_match:boundary_country:fields': ['parent.country_a', 'parent.dependency_a'], + // these options affect the `focus.country` hard filter + 'multi_match:focus_country:analyzer': 'standard', + 'multi_match:focus_country:fields': ['parent.country_a', 'parent.dependency_a'], + 'multi_match:focus_country:boost': 1.5, + + // these options affect the `focus.gid` hard filter + 'multi_match:focus_gid:analyzer': 'standard', + 'multi_match:focus_gid:fields': ['parent.*_id'], + 'multi_match:focus_gid:boost': 1.5, + 'admin:country:analyzer': 'peliasAdmin', 'admin:country:field': 'parent.country.ngram', 'admin:country:boost': 1, diff --git a/query/view/focus_multi_match.js b/query/view/focus_multi_match.js new file mode 100644 index 000000000..2bbb16687 --- /dev/null +++ b/query/view/focus_multi_match.js @@ -0,0 +1,11 @@ +const peliasQuery = require('pelias-query'); + +module.exports = (view_name) => (vs) => { + const input = vs.var(`multi_match:${view_name}:input`).get(); + + if (!input || input.length < 1) { + return null; + } + + return peliasQuery.view.leaf.multi_match(view_name)(vs); +}; diff --git a/sanitizer/_boundary_country.js b/sanitizer/_countries.js similarity index 71% rename from sanitizer/_boundary_country.js rename to sanitizer/_countries.js index 94f1d6693..60583bdf0 100644 --- a/sanitizer/_boundary_country.js +++ b/sanitizer/_countries.js @@ -2,20 +2,20 @@ const _ = require('lodash'); const nonEmptyString = (v) => _.isString(v) && !_.isEmpty(v); const iso3166 = require('../helper/iso3166'); -function _sanitize(raw, clean) { +const _sanitize = (key) => (raw, clean) => { // error & warning messages const messages = { errors: [], warnings: [] }; // target input param - let countries = raw['boundary.country']; + let countries = raw[`${key}.country`]; - // param 'boundary.country' is optional and should not + // param `*.country` is optional and should not // error when simply not set by the user if (!_.isNil(countries)) { // must be valid string if (!nonEmptyString(countries)) { - messages.errors.push('boundary.country is not a string'); + messages.errors.push(`${key}.country is not a string`); } else { // support for multi countries countries = countries.split(',').filter(nonEmptyString); @@ -23,7 +23,7 @@ function _sanitize(raw, clean) { // country list must contains at least one element if (_.isArray(countries) && _.isEmpty(countries)) { - messages.errors.push('boundary.country is empty'); + messages.errors.push(`${key}.country is empty`); } // must be a valid ISO 3166 code @@ -35,23 +35,23 @@ function _sanitize(raw, clean) { else { // the only way for boundary.country to be assigned is if input is // a string and a known ISO2 or ISO3 - clean['boundary.country'] = countries.map(country => iso3166.iso3Code(country)); + clean[`${key}.country`] = countries.map(country => iso3166.iso3Code(country)); } } } return messages; -} +}; function containsIsoCode(isoCode) { return iso3166.isISO2Code(isoCode) || iso3166.isISO3Code(isoCode); } -function _expected(){ - return [{ name: 'boundary.country' }]; +function _expected(key) { + return () => [{ name: `${key}.country` }]; } -module.exports = () => ({ - sanitize: _sanitize, - expected: _expected +module.exports = (key = 'boundary') => ({ + sanitize: _sanitize(key), + expected: _expected(key) }); diff --git a/sanitizer/_boundary_gid.js b/sanitizer/_gids.js similarity index 64% rename from sanitizer/_boundary_gid.js rename to sanitizer/_gids.js index 4ab914c5b..f921f9a62 100644 --- a/sanitizer/_boundary_gid.js +++ b/sanitizer/_gids.js @@ -1,18 +1,18 @@ const _ = require('lodash'); -function _sanitize(raw, clean) { +const _sanitize = (key) => (raw, clean) => { // error & warning messages var messages = { errors: [], warnings: [] }; // target input param - var boundary_gid = raw['boundary.gid']; + var boundary_gid = raw[`${key}.gid`]; - // param 'boundary.gid' is optional and should not + // param `${key}.gid` is optional and should not // error when simply not set by the user // must be valid string if (!_.isNil(boundary_gid)) { if (!_.isString(boundary_gid) || _.isEmpty(boundary_gid)) { - messages.errors.push('boundary.gid is not a string'); + messages.errors.push(`${key}.gid is not a string`); } else { // boundary gid should take the form of source:layer:id, @@ -22,7 +22,7 @@ function _sanitize(raw, clean) { return x !== ''; }); if ( _.inRange(fields.length, 3, 5) ) { - clean['boundary.gid'] = fields.slice(2).join(':'); + clean[`${key}.gid`] = fields.slice(2).join(':'); } else { messages.errors.push(boundary_gid + ' does not follow source:layer:id format'); @@ -31,13 +31,13 @@ function _sanitize(raw, clean) { } return messages; -} +}; -function _expected(){ - return [{ name: 'boundary.gid' }]; +function _expected(key) { + return () => [{ name: `${key}.gid` }]; } -module.exports = () => ({ - sanitize: _sanitize, - expected: _expected +module.exports = (key = 'boundary') => ({ + sanitize: _sanitize(key), + expected: _expected(key) }); diff --git a/sanitizer/autocomplete.js b/sanitizer/autocomplete.js index 34351f072..1d3ff4596 100644 --- a/sanitizer/autocomplete.js +++ b/sanitizer/autocomplete.js @@ -22,7 +22,9 @@ const paramGroups = [ ['boundary.circle.lon', 'boundary.circle.lat'], ['boundary.circle.radius'], ['boundary.country'], - ['boundary.gid'] + ['boundary.gid'], + ['focus.country'], + ['focus.gid'] ]; // middleware @@ -41,10 +43,12 @@ module.exports.middleware = (_api_pelias_config) => { 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')(), + boundary_country: require('../sanitizer/_countries')('boundary'), + focus_country: require('../sanitizer/_countries')('focus'), categories: require('../sanitizer/_categories')(), request_language: require('../sanitizer/_request_language')(), - boundary_gid: require('../sanitizer/_boundary_gid')() + boundary_gid: require('../sanitizer/_gids')('boundary'), + focus_gid: require('../sanitizer/_gids')('focus') }; return ( req, res, next ) => { diff --git a/sanitizer/nearby.js b/sanitizer/nearby.js index 182c40f8c..f8f1db51b 100644 --- a/sanitizer/nearby.js +++ b/sanitizer/nearby.js @@ -35,7 +35,7 @@ module.exports.middleware = (_api_pelias_config) => { 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')(), + boundary_country: require('../sanitizer/_countries')('boundary'), categories: require('../sanitizer/_categories')(), request_language: require('../sanitizer/_request_language')() }; diff --git a/sanitizer/reverse.js b/sanitizer/reverse.js index 33cfe28ba..45705a625 100644 --- a/sanitizer/reverse.js +++ b/sanitizer/reverse.js @@ -35,9 +35,9 @@ module.exports.middleware = (_api_pelias_config) => { 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')(), + boundary_country: require('../sanitizer/_countries')('boundary'), request_language: require('../sanitizer/_request_language')(), - boundary_gid: require('../sanitizer/_boundary_gid')() + boundary_gid: require('../sanitizer/_gids')('boundary') }; // middleware diff --git a/sanitizer/search.js b/sanitizer/search.js index 9faf84b98..f5c3eefbe 100644 --- a/sanitizer/search.js +++ b/sanitizer/search.js @@ -40,12 +40,12 @@ module.exports.middleware = (_api_pelias_config) => { 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')(), + boundary_country: require('../sanitizer/_countries')('boundary'), categories: require('../sanitizer/_categories')(), // this can go away once geonames has been abrogated geonames_warnings: require('../sanitizer/_geonames_warnings')(), request_language: require('../sanitizer/_request_language')(), - boundary_gid: require('../sanitizer/_boundary_gid')() + boundary_gid: require('../sanitizer/_gids')('boundary') }; return ( req, res, next ) => { diff --git a/sanitizer/structured_geocoding.js b/sanitizer/structured_geocoding.js index 4a8ddd640..9b1ade590 100644 --- a/sanitizer/structured_geocoding.js +++ b/sanitizer/structured_geocoding.js @@ -48,10 +48,10 @@ module.exports.middleware = (_api_pelias_config) => { 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')(), + boundary_country: require('../sanitizer/_countries')('boundary'), categories: require('../sanitizer/_categories')(), request_language: require('../sanitizer/_request_language')(), - boundary_gid: require('../sanitizer/_boundary_gid')() + boundary_gid: require('../sanitizer/_gids')('boundary') }; return ( req, res, next ) => { diff --git a/test/unit/fixture/autocomplete_focus_country.js b/test/unit/fixture/autocomplete_focus_country.js new file mode 100644 index 000000000..9432fed37 --- /dev/null +++ b/test/unit/fixture/autocomplete_focus_country.js @@ -0,0 +1,58 @@ +module.exports = { + 'query': { + 'bool': { + 'must': [ + { + 'constant_score': { + 'filter': { + 'multi_match': { + 'type': 'phrase', + 'query': 'test', + 'fields': ['name.default', 'name.en'], + 'analyzer': 'peliasQuery', + 'boost': 100, + 'slop': 3, + }, + }, + }, + }, + ], + 'should': [ + { + 'function_score': { + 'query': { 'match_all': {} }, + 'max_boost': 20, + 'functions': [ + { 'field_value_factor': { 'modifier': 'log1p', 'field': 'popularity', 'missing': 1 }, 'weight': 1 }, + ], + 'score_mode': 'first', + 'boost_mode': 'replace', + }, + }, + { + 'function_score': { + 'query': { 'match_all': {} }, + 'max_boost': 20, + 'functions': [ + { 'field_value_factor': { 'modifier': 'log1p', 'field': 'population', 'missing': 1 }, 'weight': 3 }, + ], + 'score_mode': 'first', + 'boost_mode': 'replace', + }, + }, + { + 'multi_match': { + 'type': 'best_fields', + 'query': 'ABC', + 'fields': ['parent.country_a', 'parent.dependency_a'], + 'analyzer': 'standard', + 'boost': 1.5, + }, + }, + ], + }, + }, + 'size': 20, + 'track_scores': true, + 'sort': ['_score'], +}; diff --git a/test/unit/fixture/autocomplete_focus_gid.js b/test/unit/fixture/autocomplete_focus_gid.js new file mode 100644 index 000000000..81dc0c79e --- /dev/null +++ b/test/unit/fixture/autocomplete_focus_gid.js @@ -0,0 +1,58 @@ +module.exports = { + 'query': { + 'bool': { + 'must': [ + { + 'constant_score': { + 'filter': { + 'multi_match': { + 'type': 'phrase', + 'query': 'test', + 'fields': ['name.default', 'name.en'], + 'analyzer': 'peliasQuery', + 'boost': 100, + 'slop': 3, + }, + }, + }, + }, + ], + 'should': [ + { + 'function_score': { + 'query': { 'match_all': {} }, + 'max_boost': 20, + 'functions': [ + { 'field_value_factor': { 'modifier': 'log1p', 'field': 'popularity', 'missing': 1 }, 'weight': 1 }, + ], + 'score_mode': 'first', + 'boost_mode': 'replace', + }, + }, + { + 'function_score': { + 'query': { 'match_all': {} }, + 'max_boost': 20, + 'functions': [ + { 'field_value_factor': { 'modifier': 'log1p', 'field': 'population', 'missing': 1 }, 'weight': 3 }, + ], + 'score_mode': 'first', + 'boost_mode': 'replace', + }, + }, + { + 'multi_match': { + 'type': 'best_fields', + 'query': '123', + 'fields': ['parent.*_id'], + 'analyzer': 'standard', + 'boost': 1.5, + }, + }, + ], + }, + }, + 'size': 20, + 'track_scores': true, + 'sort': ['_score'], +}; diff --git a/test/unit/query/autocomplete.js b/test/unit/query/autocomplete.js index 4651502f1..0419fdf46 100644 --- a/test/unit/query/autocomplete.js +++ b/test/unit/query/autocomplete.js @@ -365,6 +365,40 @@ module.exports.tests.query = function(test, common) { t.deepEqual(compiled.body, expected, 'autocomplete: valid boundary.gid query'); t.end(); }); + + test('valid focus.country search', function(t) { + var query = generate({ + text: 'test', + tokens: ['test'], + tokens_complete: [], + tokens_incomplete: ['test'], + 'focus.country': ['ABC'] + }); + + var compiled = JSON.parse( JSON.stringify( query ) ); + var expected = require('../fixture/autocomplete_focus_country'); + + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete: valid focus.country query'); + t.end(); + }); + + test('valid focus.gid search', function(t) { + var query = generate({ + text: 'test', + tokens: ['test'], + tokens_complete: [], + tokens_incomplete: ['test'], + 'focus.gid': '123' + }); + + var compiled = JSON.parse( JSON.stringify( query ) ); + var expected = require('../fixture/autocomplete_focus_gid'); + + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete: valid focus.gid query'); + t.end(); + }); }; module.exports.all = function (tape, common) { diff --git a/test/unit/run.js b/test/unit/run.js index 2672804d4..45dfb350a 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -79,7 +79,7 @@ var tests = [ require('./query/text_parser'), require('./query/view/boost_sources_and_layers'), require('./query/view/max_character_count_layer_filter'), - require('./sanitizer/_boundary_country'), + require('./sanitizer/_countries'), require('./sanitizer/_debug'), require('./sanitizer/_default_parameters'), require('./sanitizer/_flag_bool'), @@ -103,7 +103,7 @@ var tests = [ require('./sanitizer/_text_pelias_parser'), require('./sanitizer/_tokenizer'), require('./sanitizer/_categories'), - require('./sanitizer/_boundary_gid'), + require('./sanitizer/_gids'), require('./sanitizer/nearby'), require('./sanitizer/autocomplete'), require('./sanitizer/structured_geocoding'), diff --git a/test/unit/sanitizer/_boundary_country.js b/test/unit/sanitizer/_countries.js similarity index 74% rename from test/unit/sanitizer/_boundary_country.js rename to test/unit/sanitizer/_countries.js index d97adff0a..ebc1d0d99 100644 --- a/test/unit/sanitizer/_boundary_country.js +++ b/test/unit/sanitizer/_countries.js @@ -1,4 +1,6 @@ -var sanitizer = require('../../../sanitizer/_boundary_country')(); +const countries = require('../../../sanitizer/_countries'); +const sanitizer = countries(); +const focusSanitizer = countries('focus'); module.exports.tests = {}; @@ -39,6 +41,15 @@ module.exports.tests.sanitize_boundary_country = function(test, common) { t.end(); }); + test('iso2 focus.country in raw should set focus.country to ISO3 uppercased', function(t) { + var raw = { 'focus.country': 'aq' }; + var clean = {}; + var errorsAndWarnings = focusSanitizer.sanitize(raw, clean); + t.deepEquals(clean['focus.country'], ['ATA'], 'should be uppercased ISO3'); + t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors'); + t.end(); + }); + test('iso3 boundary.country in raw should set boundary.country to matching ISO3 uppercased', function(t) { var raw = { 'boundary.country': 'aTa' }; var clean = {}; @@ -48,6 +59,15 @@ module.exports.tests.sanitize_boundary_country = function(test, common) { t.end(); }); + test('iso3 focus.country in raw should set focus.country to matching ISO3 uppercased', function(t) { + var raw = { 'focus.country': 'aTa' }; + var clean = {}; + var errorsAndWarnings = focusSanitizer.sanitize(raw, clean); + t.deepEquals(clean['focus.country'], ['ATA'], 'should be uppercased ISO3'); + t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors'); + t.end(); + }); + test('unknown 2-character boundary.country should set boundary.country to undefined', function(t) { var raw = { 'boundary.country': 'zq' }; var clean = {}; @@ -73,6 +93,13 @@ module.exports.tests.sanitize_boundary_country = function(test, common) { t.end(); }); + test('return an array of expected custom parameters in object form for validation', (t) => { + const expected = [{ name: 'custom-name.country' }]; + const validParameters = countries('custom-name').expected(); + t.deepEquals(validParameters, expected); + t.end(); + }); + }; module.exports.all = function (tape, common) { diff --git a/test/unit/sanitizer/_boundary_gid.js b/test/unit/sanitizer/_gids.js similarity index 79% rename from test/unit/sanitizer/_boundary_gid.js rename to test/unit/sanitizer/_gids.js index a53779783..f278a2a49 100644 --- a/test/unit/sanitizer/_boundary_gid.js +++ b/test/unit/sanitizer/_gids.js @@ -1,4 +1,6 @@ -var sanitizer = require('../../../sanitizer/_boundary_gid')(); +const gids = require('../../../sanitizer/_gids'); +const sanitizer = gids(); +const focusSanitizer = gids('focus'); module.exports.tests = {}; @@ -78,6 +80,15 @@ module.exports.tests.sanitize_boundary_gid = function(test, common) { t.end(); }); + test('correctly formatted focus.gid in raw should set focus.gid', function(t) { + var raw = { 'focus.gid': 'whosonfirst:locality:123' }; + var clean = {}; + var errorsAndWarnings = focusSanitizer.sanitize(raw, clean); + t.equals(clean['focus.gid'], '123', 'should be set correctly'); + t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'valid focus_gid is set'); + t.end(); + }); + test('correctly formatted OSM-style boundary.gid in raw should set boundary.gid', function(t) { var raw = { 'boundary.gid': 'openstreetmap:street:polyline:123' }; var clean = {}; @@ -87,7 +98,14 @@ module.exports.tests.sanitize_boundary_gid = function(test, common) { t.end(); }); - + test('correctly formatted OSM-style focus.gid in raw should set focus.gid', function(t) { + var raw = { 'focus.gid': 'openstreetmap:street:polyline:123' }; + var clean = {}; + var errorsAndWarnings = focusSanitizer.sanitize(raw, clean); + t.equals(clean['focus.gid'], 'polyline:123', 'should be set correctly'); + t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'valid focus_gid is set'); + t.end(); + }); test('return an array of expected parameters in object form for validation', (t) => { const expected = [{ name: 'boundary.gid' }]; @@ -96,6 +114,13 @@ module.exports.tests.sanitize_boundary_gid = function(test, common) { t.end(); }); + test('return an array of expected custom parameters in object form for validation', (t) => { + const expected = [{ name: 'custom-name.gid' }]; + const validParameters = gids('custom-name').expected(); + t.deepEquals(validParameters, expected); + t.end(); + }); + }; module.exports.all = function (tape, common) { diff --git a/test/unit/sanitizer/autocomplete.js b/test/unit/sanitizer/autocomplete.js index f8fe7a41c..d496f3980 100644 --- a/test/unit/sanitizer/autocomplete.js +++ b/test/unit/sanitizer/autocomplete.js @@ -112,10 +112,10 @@ module.exports.tests.sanitizers = function(test, common) { } }; }, - '../sanitizer/_boundary_country': function () { + '../sanitizer/_countries': function (key) { return { sanitize: () => { - called_sanitizers.push('_boundary_country'); + called_sanitizers.push(`_${key}_country`); return { errors: [], warnings: [] }; } }; @@ -136,10 +136,10 @@ module.exports.tests.sanitizers = function(test, common) { } }; }, - '../sanitizer/_boundary_gid': () => { + '../sanitizer/_gids': (key) => { return { sanitize: () => { - called_sanitizers.push('_boundary_gid'); + called_sanitizers.push(`_${key}_gid`); return { errors: [], warnings: [] }; } }; @@ -160,9 +160,11 @@ module.exports.tests.sanitizers = function(test, common) { '_flag_bool', '_geo_autocomplete', '_boundary_country', + '_focus_country', '_categories', '_request_language', - '_boundary_gid' + '_boundary_gid', + '_focus_gid' ]; const req = {}; diff --git a/test/unit/sanitizer/nearby.js b/test/unit/sanitizer/nearby.js index 730e5c388..97e999655 100644 --- a/test/unit/sanitizer/nearby.js +++ b/test/unit/sanitizer/nearby.js @@ -86,10 +86,10 @@ module.exports.tests.sanitize = function(test, common) { } }; }, - '../sanitizer/_boundary_country': function () { + '../sanitizer/_countries': function (key) { return { sanitize: () => { - called_sanitizers.push('_boundary_country'); + called_sanitizers.push(`_${key}_country`); return { errors: [], warnings: [] }; } }; diff --git a/test/unit/sanitizer/reverse.js b/test/unit/sanitizer/reverse.js index aba8f9b55..92f8e6e94 100644 --- a/test/unit/sanitizer/reverse.js +++ b/test/unit/sanitizer/reverse.js @@ -86,10 +86,10 @@ module.exports.tests.sanitize = function(test, common) { } }; }, - '../sanitizer/_boundary_country': function () { + '../sanitizer/_countries': function (key) { return { sanitize: () => { - called_sanitizers.push('_boundary_country'); + called_sanitizers.push(`_${key}_country`); return { errors: [], warnings: [] }; } }; @@ -102,10 +102,10 @@ module.exports.tests.sanitize = function(test, common) { } }; }, - '../sanitizer/_boundary_gid': () => { + '../sanitizer/_gids': (key) => { return { sanitize: () => { - called_sanitizers.push('_boundary_gid'); + called_sanitizers.push(`_${key}_gid`); return { errors: [], warnings: [] }; } }; diff --git a/test/unit/sanitizer/search.js b/test/unit/sanitizer/search.js index b0da9e5f2..f2506320b 100644 --- a/test/unit/sanitizer/search.js +++ b/test/unit/sanitizer/search.js @@ -102,10 +102,10 @@ module.exports.tests.sanitize = (test, common) => { } }; }, - '../sanitizer/_boundary_country': function () { + '../sanitizer/_countries': function (key) { return { sanitize: () => { - called_sanitizers.push('_boundary_country'); + called_sanitizers.push(`_${key}_country`); return { errors: [], warnings: [] }; } }; @@ -134,10 +134,10 @@ module.exports.tests.sanitize = (test, common) => { } }; }, - '../sanitizer/_boundary_gid': () => { + '../sanitizer/_gids': (key) => { return { sanitize: () => { - called_sanitizers.push('_boundary_gid'); + called_sanitizers.push(`_${key}_gid`); return { errors: [], warnings: [] }; } }; diff --git a/test/unit/sanitizer/structured_geocoding.js b/test/unit/sanitizer/structured_geocoding.js index 0fb01ddbd..487015e1a 100644 --- a/test/unit/sanitizer/structured_geocoding.js +++ b/test/unit/sanitizer/structured_geocoding.js @@ -114,10 +114,10 @@ module.exports.tests.sanitize = function(test, common) { } }; }, - '../sanitizer/_boundary_country': function () { + '../sanitizer/_countries': function (key) { return { sanitize: () => { - called_sanitizers.push('_boundary_country'); + called_sanitizers.push(`_${key}_country`); return { errors: [], warnings: [] }; } }; @@ -138,10 +138,10 @@ module.exports.tests.sanitize = function(test, common) { } }; }, - '../sanitizer/_boundary_gid': () => { + '../sanitizer/_gids': (key) => { return { sanitize: () => { - called_sanitizers.push('_boundary_gid'); + called_sanitizers.push(`_${key}_gid`); return { errors: [], warnings: [] }; } };