Browse Source

Rename /search lat/lon to focus.point.lat/lon

pull/230/head
Julian Simioni 9 years ago
parent
commit
3176a61596
  1. 12
      sanitiser/_geo_search.js
  2. 10
      test/unit/sanitiser/search.js

12
sanitiser/_geo_search.js

@ -12,9 +12,17 @@ module.exports = function sanitize( req ){
params = {};
}
if( !isObject( params.focus ) ){
params.focus = {};
}
if( !isObject( params.focus.point ) ){
params.focus.point = {};
}
try {
geo_common.sanitize_coord( 'lat', clean, params.lat, latlon_is_required );
geo_common.sanitize_coord( 'lon', clean, params.lon, latlon_is_required );
geo_common.sanitize_coord( 'lat', clean, params.focus.point.lat, latlon_is_required );
geo_common.sanitize_coord( 'lon', clean, params.focus.point.lon, latlon_is_required );
geo_common.sanitize_bbox(clean, params.bbox);
}
catch (err) {

10
test/unit/sanitiser/search.js

@ -93,7 +93,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
};
test('invalid lat', function(t) {
lats.invalid.forEach( function( lat ){
sanitize({ text: 'test', lat: lat, lon: 0 }, function( err, clean ){
sanitize({ text: 'test', focus: { point: { lat: lat, lon: 0 } } }, function( err, clean ){
t.equal(err, 'invalid param \'lat\': must be >-90 and <90', lat + ' is an invalid latitude');
t.equal(clean, undefined, 'clean not set');
});
@ -102,7 +102,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
});
test('valid lat', function(t) {
lats.valid.forEach( function( lat ){
sanitize({ text: 'test', lat: lat, lon: 0 }, function( err, clean ){
sanitize({ text: 'test', focus: { point: { lat: lat, lon: 0 } } }, function( err, clean ){
var expected_lat = parseFloat( lat );
t.equal(err, undefined, 'no error');
t.deepEqual(clean.lat, expected_lat, 'clean lat set correctly (' + lat + ')');
@ -118,7 +118,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
};
test('valid lon', function(t) {
lons.valid.forEach( function( lon ){
sanitize({ text: 'test', lat: 0, lon: lon }, function( err, clean ){
sanitize({ text: 'test', focus: { point: { lat: 0, lon: lon } } }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean ));
expected.lon = parseFloat( lon );
t.equal(err, undefined, 'no error');
@ -139,7 +139,7 @@ module.exports.tests.sanitize_optional_geo = function(test, common) {
t.end();
});
test('no lat', function(t) {
sanitize({ text: 'test', lon: 0 }, function( err, clean ){
sanitize({ text: 'test', focus: { point: { lon: 0 } } }, function( err, clean ){
var expected_lon = 0;
t.equal(err, undefined, 'no error');
t.deepEqual(clean.lon, expected_lon, 'clean set correctly (without any lat)');
@ -147,7 +147,7 @@ module.exports.tests.sanitize_optional_geo = function(test, common) {
t.end();
});
test('no lon', function(t) {
sanitize({ text: 'test', lat: 0 }, function( err, clean ){
sanitize({ text: 'test', focus: { point: { lat: 0 } } }, function( err, clean ){
var expected_lat = 0;
t.equal(err, undefined, 'no error');
t.deepEqual(clean.lat, expected_lat, 'clean set correctly (without any lon)');

Loading…
Cancel
Save