|
|
@ -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: false }, |
|
|
|
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: false }; |
|
|
|
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 = false; |
|
|
|
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'); |
|
|
@ -103,7 +104,7 @@ module.exports.tests.sanitize_ids = function(test, common) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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: false }; |
|
|
|
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' ); |
|
|
|