Browse Source

Remove bbox sanitizer functionality tests from search sanitizer tests

Full functionality testing for the bbox sanitizer should be in the
sanitizer/_geo_common tests. In the search sanitizer tests, only testing
the inclusion of the correct sanitizers, and the interactions between
them, really seems to make sense.
pull/304/head
Julian Simioni 9 years ago
parent
commit
36925ca874
  1. 81
      test/unit/sanitiser/search.js

81
test/unit/sanitiser/search.js

@ -185,74 +185,25 @@ module.exports.tests.sanitize_optional_geo = function(test, common) {
}; };
module.exports.tests.sanitize_bounding_rect = function(test, common) { module.exports.tests.sanitize_bounding_rect = function(test, common) {
test('valid bounding rect', function(t) {
// convernience function to avoid refactoring the succict geojson bbox var req = {
// fixtures in to the more verbose bounding.rect format. query: {
var mapGeoJsonBboxFormatToBoundingRectFormat = function( bbox ){ text: 'test',
var split = bbox.split(','); 'boundary.rect.min_lat': -40.659,
return { 'boundary.rect.max_lat': -41.614,
'boundary.rect.min_lon': split[0], 'boundary.rect.min_lon': 174.612,
'boundary.rect.max_lat': split[1], 'boundary.rect.max_lon': 176.333
'boundary.rect.max_lon': split[2], }
'boundary.rect.min_lat': split[3]
}; };
};
var bboxes = {
invalid: [
'91;-181,-91,181', // invalid - semicolon between coordinates
'these,are,not,numbers',
'0,0,0,notANumber',
',,,',
'91, -181, -91', // invalid - missing a coordinate
'123,12', // invalid - missing coordinates
'' // invalid - empty param
].map(mapGeoJsonBboxFormatToBoundingRectFormat),
valid: [
'-179,90,34,-80', // valid top_right lon/lat, bottom_left lon/lat
'0,0,0,0',
'10,20,30,40',
'-40,-20,10,30',
'-40,-20,10,30',
'-1200,20,1000,20',
'-1400,90,1400,-90',
// wrapped latitude coordinates
'-181,90,34,-180',
'-170,91,-181,45',
'-181,91,181,-91',
'91, -181,-91,11',
'91, -11,-91,181'
].map(mapGeoJsonBboxFormatToBoundingRectFormat)
};
test('invalid bounding rect', function(t) { sanitize(req, function(){
bboxes.invalid.forEach( function( bbox ){ t.equal(req.errors[0], undefined, 'no error');
var req = { query: { text: 'test' } }; t.equal(req.clean['boundary.rect.min_lon'], parseFloat(req.query['boundary.rect.min_lon']));
extend( req.query, bbox ); t.equal(req.clean['boundary.rect.max_lat'], parseFloat(req.query['boundary.rect.max_lat']));
sanitize(req, function(){ t.equal(req.clean['boundary.rect.max_lon'], parseFloat(req.query['boundary.rect.max_lon']));
t.equal(req.clean['boundary.rect.min_lon'], undefined); t.equal(req.clean['boundary.rect.min_lat'], parseFloat(req.query['boundary.rect.min_lat']));
t.equal(req.clean['boundary.rect.max_lat'], undefined); t.end();
t.equal(req.clean['boundary.rect.max_lon'], undefined);
t.equal(req.clean['boundary.rect.min_lat'], undefined);
t.equal(req.errors.length, 1, 'bounding error');
});
});
t.end();
});
test('valid bounding rect', function(t) {
bboxes.valid.forEach( function( bbox ){
var req = { query: { text: 'test' } };
extend( req.query, bbox );
sanitize(req, function(){
t.equal(req.errors[0], undefined, 'no error');
t.equal(req.clean['boundary.rect.min_lon'], parseFloat(bbox['boundary.rect.min_lon']));
t.equal(req.clean['boundary.rect.max_lat'], parseFloat(bbox['boundary.rect.max_lat']));
t.equal(req.clean['boundary.rect.max_lon'], parseFloat(bbox['boundary.rect.max_lon']));
t.equal(req.clean['boundary.rect.min_lat'], parseFloat(bbox['boundary.rect.min_lat']));
});
}); });
t.end();
}); });
}; };

Loading…
Cancel
Save