|
|
@ -10,7 +10,7 @@ var doc = require('../../../sanitiser/doc'), |
|
|
|
defaultMissingTypeError = function(input) {
|
|
|
|
defaultMissingTypeError = function(input) {
|
|
|
|
var type = input.split(delimiter)[0]; |
|
|
|
var type = input.split(delimiter)[0]; |
|
|
|
return type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']'; }, |
|
|
|
return type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']'; }, |
|
|
|
defaultClean = { ids: [ { id: '123', type: 'geoname' } ] }, |
|
|
|
defaultClean = { ids: [ { id: '123', type: 'geoname' } ], details: true }, |
|
|
|
sanitize = function(query, cb) { _sanitize({'query':query}, cb); }, |
|
|
|
sanitize = function(query, cb) { _sanitize({'query':query}, cb); }, |
|
|
|
inputs = { |
|
|
|
inputs = { |
|
|
|
valid: [ 'geoname:1', 'osmnode:2', 'admin0:53', 'osmway:44', 'geoname:5' ], |
|
|
|
valid: [ 'geoname:1', 'osmnode:2', 'admin0:53', 'osmway:44', 'geoname:5' ], |
|
|
@ -56,7 +56,7 @@ module.exports.tests.sanitize_id = function(test, common) { |
|
|
|
test('valid input', function(t) { |
|
|
|
test('valid input', function(t) { |
|
|
|
inputs.valid.forEach( function( input ){ |
|
|
|
inputs.valid.forEach( function( input ){ |
|
|
|
var input_parts = input.split(delimiter); |
|
|
|
var input_parts = input.split(delimiter); |
|
|
|
var expected = { ids: [ { id: input_parts[1], type: input_parts[0] } ] }; |
|
|
|
var expected = { ids: [ { id: input_parts[1], type: input_parts[0] } ], details: true }; |
|
|
|
sanitize({ id: input }, function( err, clean ){ |
|
|
|
sanitize({ id: input }, function( err, clean ){ |
|
|
|
t.equal(err, undefined, 'no error (' + input + ')' ); |
|
|
|
t.equal(err, undefined, 'no error (' + input + ')' ); |
|
|
|
t.deepEqual(clean, expected, 'clean set correctly (' + input + ')'); |
|
|
|
t.deepEqual(clean, expected, 'clean set correctly (' + input + ')'); |
|
|
@ -94,6 +94,7 @@ module.exports.tests.sanitize_ids = function(test, common) { |
|
|
|
var input_parts = input.split(delimiter); |
|
|
|
var input_parts = input.split(delimiter); |
|
|
|
expected.ids.push({ id: input_parts[1], type: input_parts[0] }); |
|
|
|
expected.ids.push({ id: input_parts[1], type: input_parts[0] }); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
expected.details = true; |
|
|
|
sanitize({ id: inputs.valid }, function( err, clean ){ |
|
|
|
sanitize({ id: inputs.valid }, function( err, clean ){ |
|
|
|
t.equal(err, undefined, 'no error' ); |
|
|
|
t.equal(err, undefined, 'no error' ); |
|
|
|
t.deepEqual(clean, expected, 'clean set correctly'); |
|
|
|
t.deepEqual(clean, expected, 'clean set correctly'); |
|
|
@ -102,8 +103,47 @@ 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, true, 'details set to true'); |
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports.tests.de_dupe = function(test, common) { |
|
|
|
module.exports.tests.de_dupe = function(test, common) { |
|
|
|
var expected = { ids: [ { id: '1', type: 'geoname' }, { id: '2', type: 'osmnode' } ] }; |
|
|
|
var expected = { ids: [ { id: '1', type: 'geoname' }, { id: '2', type: 'osmnode' } ], details: true }; |
|
|
|
test('duplicate ids', function(t) { |
|
|
|
test('duplicate ids', function(t) { |
|
|
|
sanitize( { id: ['geoname:1', 'osmnode:2', 'geoname:1'] }, function( err, clean ){ |
|
|
|
sanitize( { id: ['geoname:1', 'osmnode:2', 'geoname:1'] }, function( err, clean ){ |
|
|
|
t.equal(err, undefined, 'no error' ); |
|
|
|
t.equal(err, undefined, 'no error' ); |
|
|
|