Browse Source

Flatten structure of clean for /search focus.point.lat|lon

pull/271/head
Julian Simioni 9 years ago
parent
commit
97044f655b
  1. 4
      sanitiser/_geo_search.js
  2. 12
      test/unit/sanitiser/search.js

4
sanitiser/_geo_search.js

@ -8,8 +8,8 @@ module.exports = function sanitize( raw, clean ){
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
try { try {
geo_common.sanitize_coord( 'lat', clean, raw['focus.point.lat'], LAT_LON_IS_REQUIRED ); geo_common.sanitize_coord( 'focus.point.lat', clean, raw['focus.point.lat'], LAT_LON_IS_REQUIRED );
geo_common.sanitize_coord( 'lon', clean, raw['focus.point.lon'], LAT_LON_IS_REQUIRED ); geo_common.sanitize_coord( 'focus.point.lon', clean, raw['focus.point.lon'], LAT_LON_IS_REQUIRED );
geo_common.sanitize_bbox(raw, clean); geo_common.sanitize_bbox(raw, clean);
} }
catch (err) { catch (err) {

12
test/unit/sanitiser/search.js

@ -128,7 +128,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
sanitize(req, function(){ sanitize(req, function(){
var expected_lat = parseFloat( lat ); var expected_lat = parseFloat( lat );
t.equal(req.errors[0], undefined, 'no error'); t.equal(req.errors[0], undefined, 'no error');
t.equal(req.clean.lat, expected_lat, 'clean lat set correctly (' + lat + ')'); t.equal(req.clean['focus.point.lat'], expected_lat, 'clean lat set correctly (' + lat + ')');
}); });
}); });
t.end(); t.end();
@ -145,7 +145,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
sanitize( req, function(){ sanitize( req, function(){
var expected_lon = parseFloat( lon ); var expected_lon = parseFloat( lon );
t.equal(req.errors[0], undefined, 'no error'); t.equal(req.errors[0], undefined, 'no error');
t.deepEqual(req.clean.lon, expected_lon, 'clean set correctly (' + lon + ')'); t.deepEqual(req.clean['focus.point.lon'], expected_lon, 'clean set correctly (' + lon + ')');
}); });
}); });
t.end(); t.end();
@ -157,8 +157,8 @@ module.exports.tests.sanitize_optional_geo = function(test, common) {
var req = { query: { text: 'test' } }; var req = { query: { text: 'test' } };
sanitize(req, function(){ sanitize(req, function(){
t.equal(req.errors[0], undefined, 'no error'); t.equal(req.errors[0], undefined, 'no error');
t.equal(req.clean.lat, undefined, 'clean set without lat'); t.equal(req.clean['focus.point.lat'], undefined, 'clean set without lat');
t.equal(req.clean.lon, undefined, 'clean set without lon'); t.equal(req.clean['focus.point.lon'], undefined, 'clean set without lon');
}); });
t.end(); t.end();
}); });
@ -167,7 +167,7 @@ module.exports.tests.sanitize_optional_geo = function(test, common) {
sanitize(req, function(){ sanitize(req, function(){
var expected_lon = 0; var expected_lon = 0;
t.equal(req.errors[0], undefined, 'no error'); t.equal(req.errors[0], undefined, 'no error');
t.deepEqual(req.clean.lon, expected_lon, 'clean set correctly (without any lat)'); t.deepEqual(req.clean['focus.point.lon'], expected_lon, 'clean set correctly (without any lat)');
}); });
t.end(); t.end();
}); });
@ -176,7 +176,7 @@ module.exports.tests.sanitize_optional_geo = function(test, common) {
sanitize(req, function(){ sanitize(req, function(){
var expected_lat = 0; var expected_lat = 0;
t.equal(req.errors[0], undefined, 'no error'); t.equal(req.errors[0], undefined, 'no error');
t.deepEqual(req.clean.lat, expected_lat, 'clean set correctly (without any lon)'); t.deepEqual(req.clean['focus.point.lat'], expected_lat, 'clean set correctly (without any lon)');
}); });
t.end(); t.end();
}); });

Loading…
Cancel
Save