Browse Source

refactored _details tests to only _details sanitizer

pull/248/head
Stephen Hess 9 years ago
parent
commit
2f5a5b1972
  1. 48
      test/unit/sanitiser/_details.js

48
test/unit/sanitiser/_details.js

@ -1,45 +1,43 @@
var search = require('../../../sanitiser/search'), var sanitize = require('../../../sanitiser/_details');
_sanitize = search.sanitize,
sanitize = function(query, cb) { _sanitize({'query':query}, cb); };
module.exports.tests = {}; module.exports.tests = {};
module.exports.tests.sanitize_details = function(test, common) { module.exports.tests.sanitize_details = function(test, common) {
var invalid_values = [null, -1, 123, NaN, 'abc']; var invalid_values = [null, -1, 123, NaN, 'abc'];
invalid_values.forEach(function(details) { invalid_values.forEach(function(detailsValue) {
test('invalid details param ' + details, function(t) { test('invalid details param ' + detailsValue, function(t) {
sanitize({ text: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){ var req = {query: { details: detailsValue }};
t.equal(clean.details, false, 'default details set (to false)'); sanitize(req);
t.end(); t.equal(req.clean.details, false, 'default details set (to false)');
}); t.end();
}); });
}); });
var valid_values = ['true', true, 1, '1', 'yes', 'y']; var valid_values = ['true', true, 1, '1', 'yes', 'y'];
valid_values.forEach(function(details) { valid_values.forEach(function(detailsValue) {
test('valid details param ' + details, function(t) { test('valid details param ' + detailsValue, function(t) {
sanitize({ text: 'test', details: details }, function( err, clean ){ var req = {query: { details: detailsValue }};
t.equal(clean.details, true, 'details set to true'); sanitize(req);
t.end(); t.equal(req.clean.details, true, 'details set to true');
}); t.end();
}); });
}); });
var valid_false_values = ['false', false, 0, '0', 'no', 'n']; var valid_false_values = ['false', false, 0, '0', 'no', 'n'];
valid_false_values.forEach(function(details) { valid_false_values.forEach(function(detailsValue) {
test('test setting false explicitly ' + details, function(t) { test('test setting false explicitly ' + detailsValue, function(t) {
sanitize({ text: 'test', details: details }, function( err, clean ){ var req = {query: { details: detailsValue }};
t.equal(clean.details, false, 'details set to false'); sanitize(req);
t.end(); t.equal(req.clean.details, false, 'details set to false');
}); t.end();
}); });
}); });
test('test default behavior', function(t) { test('test default behavior', function(t) {
sanitize({ text: 'test' }, function( err, clean ){ var req = {query: {}};
t.equal(clean.details, true, 'details set to true'); sanitize(req);
t.end(); t.equal(req.clean.details, true, 'details set to true');
}); t.end();
}); });
}; };

Loading…
Cancel
Save