From e52c9e4ab92140ee9c113cf9fa3f5af3f2470050 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Thu, 10 Sep 2015 16:34:49 -0400 Subject: [PATCH] moved details tests out to separate file --- test/unit/run.js | 1 + test/unit/sanitiser/_details.js | 55 +++++++++++++++++++++++++++++++++ test/unit/sanitiser/search.js | 41 +----------------------- 3 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 test/unit/sanitiser/_details.js diff --git a/test/unit/run.js b/test/unit/run.js index 2ca9be3e..6b8611d0 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -8,6 +8,7 @@ var tests = [ require('./controller/search'), require('./service/mget'), require('./service/search'), + require('./sanitiser/_details'), require('./sanitiser/_source'), require('./sanitiser/search'), require('./sanitiser/reverse'), diff --git a/test/unit/sanitiser/_details.js b/test/unit/sanitiser/_details.js new file mode 100644 index 00000000..a3379918 --- /dev/null +++ b/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); + } +}; diff --git a/test/unit/sanitiser/search.js b/test/unit/sanitiser/search.js index 8969fab6..9cba990c 100644 --- a/test/unit/sanitiser/search.js +++ b/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) { 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 ){ sanitize({ text: text }, function( err, clean ){ 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) { test('unspecified', function(t) { sanitize({ layers: undefined, text: 'test' }, function( err, clean ){