Browse Source

moved details tests out to separate file

pull/248/head
Stephen Hess 9 years ago
parent
commit
e52c9e4ab9
  1. 1
      test/unit/run.js
  2. 55
      test/unit/sanitiser/_details.js
  3. 41
      test/unit/sanitiser/search.js

1
test/unit/run.js

@ -8,6 +8,7 @@ var tests = [
require('./controller/search'), require('./controller/search'),
require('./service/mget'), require('./service/mget'),
require('./service/search'), require('./service/search'),
require('./sanitiser/_details'),
require('./sanitiser/_source'), require('./sanitiser/_source'),
require('./sanitiser/search'), require('./sanitiser/search'),
require('./sanitiser/reverse'), require('./sanitiser/reverse'),

55
test/unit/sanitiser/_details.js

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

41
test/unit/sanitiser/search.js

@ -70,7 +70,7 @@ module.exports.tests.sanitise_valid_text = function(test, common) {
module.exports.tests.sanitize_text_with_delim = function(test, common) { module.exports.tests.sanitize_text_with_delim = function(test, common) {
var texts = [ 'a,bcd', '123 main st, admin1', ',,,', ' ' ]; var texts = [ 'a,bcd', '123 main st, admin1', ',,,', ' ' ];
test('valid texts with a comma', function(t) { test('valid texts with a comma', function(t) {
texts.forEach( function( text ){ texts.forEach( function( text ){
sanitize({ text: text }, function( err, clean ){ sanitize({ text: text }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean )); var expected = JSON.parse(JSON.stringify( defaultClean ));
@ -234,45 +234,6 @@ module.exports.tests.sanitize_size = function(test, common) {
}); });
}; };
module.exports.tests.sanitize_details = function(test, common) {
var invalid_values = [null, -1, 123, NaN, 'abc'];
invalid_values.forEach(function(details) {
test('invalid details param ' + details, function(t) {
sanitize({ text: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
t.equal(clean.details, false, 'default details set (to false)');
t.end();
});
});
});
var valid_values = ['true', true, 1, '1', 'yes', 'y'];
valid_values.forEach(function(details) {
test('valid details param ' + details, function(t) {
sanitize({ text: 'test', details: details }, function( err, clean ){
t.equal(clean.details, true, 'details set to true');
t.end();
});
});
});
var valid_false_values = ['false', false, 0, '0', 'no', 'n'];
valid_false_values.forEach(function(details) {
test('test setting false explicitly ' + details, function(t) {
sanitize({ text: 'test', details: details }, function( err, clean ){
t.equal(clean.details, false, 'details set to false');
t.end();
});
});
});
test('test default behavior', function(t) {
sanitize({ text: 'test' }, function( err, clean ){
t.equal(clean.details, true, 'details set to true');
t.end();
});
});
};
module.exports.tests.sanitize_layers = function(test, common) { module.exports.tests.sanitize_layers = function(test, common) {
test('unspecified', function(t) { test('unspecified', function(t) {
sanitize({ layers: undefined, text: 'test' }, function( err, clean ){ sanitize({ layers: undefined, text: 'test' }, function( err, clean ){

Loading…
Cancel
Save