Browse Source

added location_bias sanitizer to autocomplete, search, and structured_geocoding

pull/928/head
Lily He 7 years ago
parent
commit
2e2ae9b005
  1. 4
      sanitizer/_location_bias.js
  2. 1
      sanitizer/autocomplete.js
  3. 1
      sanitizer/search.js
  4. 1
      sanitizer/structured_geocoding.js
  5. 2
      test/unit/sanitizer/autocomplete.js
  6. 6
      test/unit/sanitizer/search.js
  7. 5
      test/unit/sanitizer/structured_geocoding.js

4
sanitizer/_location_bias.js

@ -5,7 +5,9 @@ var _ = require('lodash');
function setup(defaultParameters){
return function setLocationBias(req, res, next){
if (_.isUndefined(req.clean) || _.isUndefined(defaultParameters['focus.point.lat']) || _.isUndefined(defaultParameters['focus.point.lon'])) {
if (_.isUndefined(req.clean) ||
_.isUndefined(defaultParameters['focus.point.lat']) ||
_.isUndefined(defaultParameters['focus.point.lon'])) {
return next();
}
req.clean['focus.point.lat'] = defaultParameters['focus.point.lat'];

1
sanitizer/autocomplete.js

@ -11,6 +11,7 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'),
// 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),
location_bias: require('../sanitizer/_location_bias'),
geo_autocomplete: require('../sanitizer/_geo_autocomplete'),
boundary_country: require('../sanitizer/_boundary_country'),
categories: require('../sanitizer/_categories')

1
sanitizer/search.js

@ -13,6 +13,7 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'),
// 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),
location_bias: require('../sanitizer/_location_bias'),
geo_search: require('../sanitizer/_geo_search'),
boundary_country: require('../sanitizer/_boundary_country'),
categories: require('../sanitizer/_categories'),

1
sanitizer/structured_geocoding.js

@ -13,6 +13,7 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'),
// 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),
location_bias: require('../sanitizer/_location_bias'),
geo_search: require('../sanitizer/_geo_search'),
boundary_country: require('../sanitizer/_boundary_country'),
categories: require('../sanitizer/_categories')

2
test/unit/sanitizer/autocomplete.js

@ -6,7 +6,7 @@ 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'
'sources_and_layers', 'private', 'location_bias', 'geo_autocomplete', 'boundary_country', 'categories'
];
t.deepEqual(Object.keys(autocomplete.sanitizer_list), expected);
t.end();

6
test/unit/sanitizer/search.js

@ -87,7 +87,12 @@ module.exports.tests.sanitize = (test, common) => {
'../sanitizer/_geonames_warnings': () => {
called_sanitizers.push('_geonames_warnings');
return { errors: [], warnings: [] };
},
'../sanitizer/_location_bias': () => {
called_sanitizers.push('_location_bias');
return { errors: [], warnings: [] };
}
});
const expected_sanitizers = [
@ -101,6 +106,7 @@ module.exports.tests.sanitize = (test, common) => {
'_targets/sources',
'_sources_and_layers',
'_flag_bool',
'_location_bias',
'_geo_search',
'_boundary_country',
'_categories',

5
test/unit/sanitizer/structured_geocoding.js

@ -83,6 +83,10 @@ module.exports.tests.sanitize = function(test, common) {
called_sanitizers.push('_categories');
return { errors: [], warnings: [] };
},
'../sanitizer/_location_bias': () => {
called_sanitizers.push('_location_bias');
return { errors: [], warnings: [] };
}
});
var expected_sanitizers = [
@ -96,6 +100,7 @@ module.exports.tests.sanitize = function(test, common) {
'_targets/sources',
'_sources_and_layers',
'_flag_bool',
'_location_bias',
'_geo_search',
'_boundary_country',
'_categories'

Loading…
Cancel
Save