Browse Source

Leave clean.ids undefined on error

pull/273/head
Julian Simioni 9 years ago
parent
commit
1b6c61c92e
  1. 8
      sanitiser/_ids.js
  2. 2
      test/ciao/place/missing_id.coffee
  3. 6
      test/unit/sanitiser/place.js

8
sanitiser/_ids.js

@ -46,7 +46,7 @@ function sanitize( raw, clean ){
}); });
// init 'clean.ids' // init 'clean.ids'
clean.ids = []; var validIds = [];
// cycle through raw ids and set those which are valid // cycle through raw ids and set those which are valid
rawIds.forEach( function( rawId ){ rawIds.forEach( function( rawId ){
@ -74,7 +74,7 @@ function sanitize( raw, clean ){
} }
// add valid id to 'clean.ids' array // add valid id to 'clean.ids' array
else { else {
clean.ids.push({ validIds.push({
id: id, id: id,
type: type type: type
}); });
@ -82,6 +82,10 @@ function sanitize( raw, clean ){
}); });
if (validIds.length > 0) {
clean.ids = validIds;
}
return messages; return messages;
} }

2
test/ciao/place/missing_id.coffee

@ -30,5 +30,5 @@ json.geocoding.errors.should.eql [ 'invalid param \'ids\': text length, must be
should.not.exist json.geocoding.warnings should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['ids'].should.eql [] should.not.exist json.geocoding.query['ids']
should.not.exist json.geocoding.query['size'] should.not.exist json.geocoding.query['size']

6
test/unit/sanitiser/place.js

@ -18,8 +18,6 @@ var place = require('../../../sanitiser/place'),
}; };
// 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.
var emptyClean = { ids: [], private: false };
module.exports.tests = {}; module.exports.tests = {};
module.exports.tests.interface = function(test, common) { module.exports.tests.interface = function(test, common) {
@ -51,7 +49,7 @@ module.exports.tests.sanitize_id = function(test, common) {
t.equal(req.errors[0], defaultMissingTypeError(input), input + ' is an unknown type'); break; t.equal(req.errors[0], defaultMissingTypeError(input), input + ' is an unknown type'); break;
default: break; default: break;
} }
t.deepEqual(req.clean, emptyClean, 'clean only has default values set'); t.equal(req.clean.ids, undefined, 'clean has no ids value set');
}); });
}); });
t.end(); t.end();
@ -86,7 +84,7 @@ module.exports.tests.sanitize_ids = function(test, common) {
]; ];
sanitize(req, function(){ sanitize(req, function(){
t.deepEqual(req.errors, expected); t.deepEqual(req.errors, expected);
t.deepEqual(req.clean, emptyClean, 'clean only has default values set'); t.equal(req.clean.ids, undefined, 'clean has no ids value set');
}); });
t.end(); t.end();
}); });

Loading…
Cancel
Save