Browse Source

Remove categories from response json

pull/270/head
Diana Shkolnikov 9 years ago
parent
commit
f1fdc2bc26
  1. 1
      helper/geojsonify.js
  2. 1
      sanitiser/reverse.js
  3. 1
      sanitiser/search.js
  4. 4
      test/unit/helper/geojsonify.js
  5. 46
      test/unit/sanitiser/reverse.js
  6. 4
      test/unit/sanitiser/search.js

1
helper/geojsonify.js

@ -8,7 +8,6 @@ var GeoJSON = require('geojson'),
var DETAILS_PROPS = [ var DETAILS_PROPS = [
'housenumber', 'housenumber',
'street', 'street',
'category',
'postalcode', 'postalcode',
'country_a', 'country_a',
'country', 'country',

1
sanitiser/reverse.js

@ -6,7 +6,6 @@ var sanitizeAll = require('../sanitiser/sanitizeAll'),
size: require('../sanitiser/_size'), size: require('../sanitiser/_size'),
private: require('../sanitiser/_flag_bool')('private', false), private: require('../sanitiser/_flag_bool')('private', false),
geo_reverse: require('../sanitiser/_geo_reverse'), geo_reverse: require('../sanitiser/_geo_reverse'),
categories: require('../sanitiser/_categories'),
boundary_country: require('../sanitiser/_boundary_country'), boundary_country: require('../sanitiser/_boundary_country'),
}; };

1
sanitiser/search.js

@ -7,7 +7,6 @@ var sanitizeAll = require('../sanitiser/sanitizeAll'),
sources: require('../sanitiser/_targets')('sources', require( '../query/sources' )), sources: require('../sanitiser/_targets')('sources', require( '../query/sources' )),
private: require('../sanitiser/_flag_bool')('private', false), private: require('../sanitiser/_flag_bool')('private', false),
geo_search: require('../sanitiser/_geo_search'), geo_search: require('../sanitiser/_geo_search'),
categories: require('../sanitiser/_categories'),
boundary_country: require('../sanitiser/_boundary_country'), boundary_country: require('../sanitiser/_boundary_country'),
}; };

4
test/unit/helper/geojsonify.js

@ -153,7 +153,6 @@ module.exports.tests.search = function(test, common) {
'localadmin': 'test1', 'localadmin': 'test1',
'locality': 'test2', 'locality': 'test2',
'neighbourhood': 'test3', 'neighbourhood': 'test3',
'category': ['food', 'nightlife'],
'housenumber': '13', 'housenumber': '13',
'street': 'Liverpool Road', 'street': 'Liverpool Road',
'postalcode': 'N1 0RW' 'postalcode': 'N1 0RW'
@ -206,8 +205,7 @@ module.exports.tests.search = function(test, common) {
'county': 'New York', 'county': 'New York',
'localadmin': 'Manhattan', 'localadmin': 'Manhattan',
'locality': 'New York', 'locality': 'New York',
'neighbourhood': 'Koreatown', 'neighbourhood': 'Koreatown'
'category': ['tourism', 'transport']
} }
} }
] ]

46
test/unit/sanitiser/reverse.js

@ -11,13 +11,12 @@ var reverse = require('../../../sanitiser/reverse'),
lon: 0, lon: 0,
size: 10, size: 10,
private: false, private: false,
categories: [],
boundary: { } boundary: { }
}; };
// these are the default values you would expect when no input params are specified. // these are the default values you would expect when no input params are specified.
// @todo: why is this different from $defaultClean? // @todo: why is this different from $defaultClean?
var emptyClean = { boundary: {}, categories: [], private: false, size: 10, types: {} }; var emptyClean = { boundary: {}, private: false, size: 10, types: {} };
module.exports.tests = {}; module.exports.tests = {};
@ -36,7 +35,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.sanitisers = function(test, common) { module.exports.tests.sanitisers = function(test, common) {
test('check sanitiser list', function (t) { test('check sanitiser list', function (t) {
var expected = ['layers', 'sources', 'size', 'private', 'geo_reverse', 'categories', 'boundary_country']; var expected = ['layers', 'sources', 'size', 'private', 'geo_reverse', 'boundary_country'];
t.deepEqual(Object.keys(reverse.sanitiser_list), expected); t.deepEqual(Object.keys(reverse.sanitiser_list), expected);
t.end(); t.end();
}); });
@ -104,7 +103,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
var req = { query: { 'point.lat': 0, 'point.lon': lon } }; var req = { query: { 'point.lat': 0, 'point.lon': lon } };
// @todo: why is lat set? // @todo: why is lat set?
var expected = { boundary: {}, categories: [], lat: 0, private: false, size: 10, types: {} }; var expected = { boundary: {}, lat: 0, private: false, size: 10, types: {} };
sanitize(req, function(){ sanitize(req, function(){
t.equal(req.errors[0], 'missing param \'lon\'', 'longitude is a required field'); t.equal(req.errors[0], 'missing param \'lon\'', 'longitude is a required field');
t.deepEqual(req.clean, expected, 'clean only has default values set'); t.deepEqual(req.clean, expected, 'clean only has default values set');
@ -181,45 +180,6 @@ module.exports.tests.sanitize_private = function(test, common) {
}); });
}; };
module.exports.tests.sanitize_categories = function(test, common) {
var req = { query: { 'point.lat': 0, 'point.lon': 0 } };
test('unspecified', function(t) {
req.query.categories = undefined;
sanitize(req, function(){
t.deepEqual(req.clean.categories, defaultClean.categories, 'default to empty categories array');
t.end();
});
});
test('single category', function(t) {
req.query.categories = 'food';
sanitize(req, function(){
t.deepEqual(req.clean.categories, ['food'], 'category set');
t.end();
});
});
test('multiple categories', function(t) {
req.query.categories = 'food,education,nightlife';
sanitize(req, function(){
t.deepEqual(req.clean.categories, ['food', 'education', 'nightlife'], 'categories set');
t.end();
});
});
test('whitespace and empty strings', function(t) {
req.query.categories = 'food, , nightlife ,';
sanitize(req, function(){
t.deepEqual(req.clean.categories, ['food', 'nightlife'], 'categories set');
t.end();
});
});
test('all empty strings', function(t) {
req.query.categories = ', , ,';
sanitize(req, function(){
t.deepEqual(req.clean.categories, defaultClean.categories, 'empty strings filtered out');
t.end();
});
});
};
module.exports.tests.middleware_success = function(test, common) { module.exports.tests.middleware_success = function(test, common) {
test('middleware success', function(t) { test('middleware success', function(t) {
var req = { query: { 'point.lat': 0, 'point.lon': 0 }}; var req = { query: { 'point.lat': 0, 'point.lon': 0 }};

4
test/unit/sanitiser/search.js

@ -15,7 +15,7 @@ var search = require('../../../sanitiser/search'),
// these are the default values you would expect when no input params are specified. // these are the default values you would expect when no input params are specified.
// @todo: why is this different from $defaultClean? // @todo: why is this different from $defaultClean?
var emptyClean = { boundary: {}, categories: [], private: false, size: 10, types: {} }; var emptyClean = { boundary: {}, private: false, size: 10, types: {} };
module.exports.tests = {}; module.exports.tests = {};
@ -34,7 +34,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.sanitisers = function(test, common) { module.exports.tests.sanitisers = function(test, common) {
test('check sanitiser list', function (t) { test('check sanitiser list', function (t) {
var expected = ['text', 'size', 'layers', 'sources', 'private', 'geo_search', 'categories', 'boundary_country' ]; var expected = ['text', 'size', 'layers', 'sources', 'private', 'geo_search', 'boundary_country' ];
t.deepEqual(Object.keys(search.sanitiser_list), expected); t.deepEqual(Object.keys(search.sanitiser_list), expected);
t.end(); t.end();
}); });

Loading…
Cancel
Save