Browse Source

grouping test cases when appropriate

pull/35/head
Harish Krishna 10 years ago
parent
commit
ed5a1923d3
  1. 19
      test/unit/sanitiser/get.js
  2. 37
      test/unit/sanitiser/suggest.js

19
test/unit/sanitiser/get.js

@ -43,32 +43,33 @@ module.exports.tests.sanitize_id_and_type = function(test, common) {
]
};
inputs.invalid.forEach( function( input ){
test('invalid id and/or type', function(t) {
inputs.invalid.forEach( function( input ){
sanitize({ id: input.id, type: input.type }, function( err, clean ){
switch (err) {
case defaultIdError:
t.equal(err, defaultIdError, 'missing id'); break;
t.equal(err, defaultIdError, input.id + ' is invalid (missing id)'); break;
case defaultTypeError:
t.equal(err, defaultTypeError, 'missing type'); break;
t.equal(err, defaultTypeError, input.type + ' is invalid (missing type)'); break;
case defaultMissingTypeError:
t.equal(err, defaultMissingTypeError, 'unknown type'); break;
t.equal(err, defaultMissingTypeError, input.type + ' is an unknown type'); break;
default: break;
}
t.equal(clean, undefined, 'clean not set');
t.end();
});
});
t.end();
});
inputs.valid.forEach( function( input ){
test('valid id and/or type', function(t) {
inputs.valid.forEach( function( input ){
var expected = { id: input.id, type: input.type };
sanitize({ id: input.id, type: input.type, }, function( err, clean ){
t.equal(err, undefined, 'no error');
t.deepEqual(clean, expected, 'clean set correctly');
t.end();
t.equal(err, undefined, 'no error (' + input.id + ', ' + input.type + ')' );
t.deepEqual(clean, expected, 'clean set correctly (' + input.id + ', ' + input.type + ')');
});
});
t.end();
});
};

37
test/unit/sanitiser/suggest.js

@ -26,25 +26,25 @@ module.exports.tests.sanitize_input = function(test, common) {
invalid: [ '', 100, null, undefined, new Date() ],
valid: [ 'a', 'aa', 'aaaaaaaa' ]
};
inputs.invalid.forEach( function( input ){
test('invalid input', function(t) {
inputs.invalid.forEach( function( input ){
sanitize({ input: input, lat: 0, lon: 0 }, function( err, clean ){
t.equal(err, 'invalid param \'input\': text length, must be >0', 'invalid input');
t.equal(err, 'invalid param \'input\': text length, must be >0', input + ' is an invalid input');
t.equal(clean, undefined, 'clean not set');
t.end();
});
});
t.end();
});
inputs.valid.forEach( function( input ){
test('valid input', function(t) {
inputs.valid.forEach( function( input ){
sanitize({ input: input, lat: 0, lon: 0 }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean ));
expected.input = input;
t.equal(err, undefined, 'no error');
t.deepEqual(clean, expected, 'clean set correctly');
t.end();
t.deepEqual(clean, expected, 'clean set correctly (' + input + ')');
});
});
t.end();
});
};
@ -53,25 +53,25 @@ module.exports.tests.sanitize_lat = function(test, common) {
invalid: [ -181, -120, -91, 91, 120, 181 ],
valid: [ 0, 45, 90, -0, '0', '45', '90' ]
};
lats.invalid.forEach( function( lat ){
test('invalid lat', function(t) {
lats.invalid.forEach( function( lat ){
sanitize({ input: 'test', lat: lat, lon: 0 }, function( err, clean ){
t.equal(err, 'invalid param \'lat\': must be >-90 and <90', 'invalid latitude');
t.equal(err, 'invalid param \'lat\': must be >-90 and <90', lat + ' is an invalid latitude');
t.equal(clean, undefined, 'clean not set');
t.end();
});
});
t.end();
});
lats.valid.forEach( function( lat ){
test('valid lat', function(t) {
lats.valid.forEach( function( lat ){
sanitize({ input: 'test', lat: lat, lon: 0 }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean ));
expected.lat = parseFloat( lat );
t.equal(err, undefined, 'no error');
t.deepEqual(clean, expected, 'clean set correctly');
t.end();
t.deepEqual(clean, expected, 'clean set correctly (' + lat + ')');
});
});
t.end();
});
};
@ -80,25 +80,26 @@ module.exports.tests.sanitize_lon = function(test, common) {
invalid: [ -360, -181, 181, 360 ],
valid: [ -180, -1, -0, 0, 45, 90, '-180', '0', '180' ]
};
lons.invalid.forEach( function( lon ){
test('invalid lon', function(t) {
lons.invalid.forEach( function( lon ){
sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){
t.equal(err, 'invalid param \'lon\': must be >-180 and <180', 'invalid longitude');
t.equal(err, 'invalid param \'lon\': must be >-180 and <180', lon + ' is an invalid longitude');
t.equal(clean, undefined, 'clean not set');
t.end();
});
});
t.end();
});
lons.valid.forEach( function( lon ){
test('valid lon', function(t) {
lons.valid.forEach( function( lon ){
sanitize({ input: 'test', lat: 0, lon: lon }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean ));
expected.lon = parseFloat( lon );
t.equal(err, undefined, 'no error');
t.deepEqual(clean, expected, 'clean set correctly');
t.end();
t.deepEqual(clean, expected, 'clean set correctly (' + lon + ')');
});
});
t.end();
});
};

Loading…
Cancel
Save