Browse Source

oh so many more tests!

pull/103/head
Harish Krishna 10 years ago
parent
commit
af45b4743c
  1. 39
      test/unit/sanitiser/doc.js
  2. 41
      test/unit/sanitiser/reverse.js
  3. 39
      test/unit/sanitiser/search.js
  4. 39
      test/unit/sanitiser/suggest.js

39
test/unit/sanitiser/doc.js

@ -103,6 +103,45 @@ module.exports.tests.sanitize_ids = 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({ id:'geoname:123', details: details }, function( err, clean ){
t.equal(clean.details, false, 'default details set (to false)');
t.end();
});
});
});
var valid_values = ['true', true, 1];
valid_values.forEach(function(details) {
test('valid details param ' + details, function(t) {
sanitize({ id:'geoname:123', details: details }, function( err, clean ){
t.equal(clean.details, true, 'details set to true');
t.end();
});
});
});
var valid_false_values = ['false', false, 0];
valid_false_values.forEach(function(details) {
test('test setting false explicitly ' + details, function(t) {
sanitize({ id:'geoname:123', details: details }, function( err, clean ){
t.equal(clean.details, false, 'details set to false');
t.end();
});
});
});
test('test default behavior', function(t) {
sanitize({ id:'geoname:123' }, function( err, clean ){
t.equal(clean.details, false, 'details set to false');
t.end();
});
});
};
module.exports.tests.de_dupe = function(test, common) {
var expected = { ids: [ { id: '1', type: 'geoname' }, { id: '2', type: 'osmnode' } ], details: false };
test('duplicate ids', function(t) {

41
test/unit/sanitiser/reverse.js

@ -9,7 +9,7 @@ var suggest = require('../../../sanitiser/reverse'),
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
lon: 0,
size: 1,
details: false
details: true
},
sanitize = function(query, cb) { _sanitize({'query':query}, cb); };
@ -125,6 +125,45 @@ 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({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
t.equal(clean.details, false, 'details set to false');
t.end();
});
});
});
var valid_values = [true, 'true', 1];
valid_values.forEach(function(details) {
test('valid details param ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
t.equal(clean.details, true, 'details set to true');
t.end();
});
});
});
test('test default behavior', function(t) {
sanitize({ input: 'test', lat: 0, lon: 0 }, function( err, clean ){
t.equal(clean.details, true, 'details set to true');
t.end();
});
});
var valid_false_values = ['false', false, 0];
valid_false_values.forEach(function(details) {
test('test setting false explicitly ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
t.equal(clean.details, false, 'details set to false');
t.end();
});
});
});
};
module.exports.tests.sanitize_layers = function(test, common) {
test('unspecified', function(t) {
sanitize({ layers: undefined, input: 'test', lat: 0, lon: 0 }, function( err, clean ){

39
test/unit/sanitiser/search.js

@ -267,6 +267,45 @@ 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({ input: '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];
valid_values.forEach(function(details) {
test('valid details param ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
t.equal(clean.details, true, 'details set to true');
t.end();
});
});
});
var valid_false_values = ['false', false, 0];
valid_false_values.forEach(function(details) {
test('test setting false explicitly ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
t.equal(clean.details, false, 'details set to false');
t.end();
});
});
});
test('test default behavior', function(t) {
sanitize({ input: 'test', lat: 0, lon: 0 }, function( err, clean ){
t.equal(clean.details, false, 'details set to false');
t.end();
});
});
};
module.exports.tests.sanitize_layers = function(test, common) {
test('unspecified', function(t) {
sanitize({ layers: undefined, input: 'test' }, function( err, clean ){

39
test/unit/sanitiser/suggest.js

@ -236,6 +236,45 @@ 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({ input: '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];
valid_values.forEach(function(details) {
test('valid details param ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
t.equal(clean.details, true, 'details set to true');
t.end();
});
});
});
var valid_false_values = ['false', false, 0];
valid_false_values.forEach(function(details) {
test('test setting false explicitly ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
t.equal(clean.details, false, 'details set to false');
t.end();
});
});
});
test('test default behavior', function(t) {
sanitize({ input: 'test', lat: 0, lon: 0 }, function( err, clean ){
t.equal(clean.details, false, 'details set to false');
t.end();
});
});
};
module.exports.tests.sanitize_layers = function(test, common) {
test('unspecified', function(t) {
sanitize({ layers: undefined, input: 'test', lat: 0, lon: 0 }, function( err, clean ){

Loading…
Cancel
Save