mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.5 KiB
129 lines
3.5 KiB
9 years ago
|
var type_mapping = require('../../../helper/type_mapping');
|
||
8 years ago
|
var sanitize = require( '../../../sanitizer/_targets' )('sources', type_mapping.source_mapping);
|
||
9 years ago
|
|
||
9 years ago
|
var success_messages = { error: false };
|
||
9 years ago
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.no_sources = function(test, common) {
|
||
9 years ago
|
test('sources is not set', function(t) {
|
||
9 years ago
|
var req = {
|
||
9 years ago
|
query: { },
|
||
|
clean: { }
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
var messages = sanitize(req.query, req.clean);
|
||
9 years ago
|
|
||
9 years ago
|
t.equal(req.clean.sources, undefined, 'no sources should be defined');
|
||
9 years ago
|
t.deepEqual(messages.errors, [], 'no error returned');
|
||
|
t.deepEqual(messages.warnings, [], 'no warnings returned');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
|
||
|
test('source is empty string', function(t) {
|
||
|
var req = {
|
||
|
query: {
|
||
9 years ago
|
sources: ''
|
||
9 years ago
|
},
|
||
|
clean: { }
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
var expected_error = 'sources parameter cannot be an empty string. ' +
|
||
9 years ago
|
'Valid options: osm,oa,gn,wof,openstreetmap,openaddresses,geonames,whosonfirst';
|
||
9 years ago
|
|
||
9 years ago
|
var messages = sanitize(req.query, req.clean);
|
||
9 years ago
|
|
||
9 years ago
|
t.equal(req.clean.sources, undefined, 'no sources should be defined');
|
||
9 years ago
|
t.deepEqual(messages.errors.length, 1, 'error returned');
|
||
|
t.deepEqual(messages.errors[0], expected_error, 'error returned');
|
||
|
t.deepEqual(messages.warnings, [], 'no warnings returned');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.tests.valid_sources = function(test, common) {
|
||
|
test('geonames source', function(t) {
|
||
|
var req = {
|
||
|
query: {
|
||
9 years ago
|
sources: 'geonames'
|
||
9 years ago
|
},
|
||
|
clean: { }
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
var messages = sanitize(req.query, req.clean);
|
||
9 years ago
|
|
||
9 years ago
|
t.deepEqual(req.clean.sources, ['geonames'], 'sources should contain geonames');
|
||
9 years ago
|
t.deepEqual(messages.errors, [], 'no error returned');
|
||
|
t.deepEqual(messages.warnings, [], 'no warnings returned');
|
||
|
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
|
||
9 years ago
|
test('openstreetmap (abbreviated) source', function(t) {
|
||
9 years ago
|
var req = {
|
||
|
query: {
|
||
9 years ago
|
sources: 'osm'
|
||
9 years ago
|
},
|
||
|
clean: { }
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
var messages = sanitize(req.query, req.clean);
|
||
9 years ago
|
|
||
9 years ago
|
t.deepEqual(req.clean.sources, ['openstreetmap'], 'abbreviation is expanded to full version');
|
||
9 years ago
|
t.deepEqual(messages.errors, [], 'no error returned');
|
||
|
t.deepEqual(messages.warnings, [], 'no warnings returned');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
|
||
|
test('multiple sources', function(t) {
|
||
|
var req = {
|
||
|
query: {
|
||
9 years ago
|
sources: 'openstreetmap,openaddresses'
|
||
9 years ago
|
},
|
||
|
clean: { }
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
var messages = sanitize(req.query, req.clean);
|
||
9 years ago
|
|
||
9 years ago
|
t.deepEqual(req.clean.sources, ['openstreetmap', 'openaddresses'],
|
||
|
'clean.sources should contain openstreetmap and openadresses');
|
||
9 years ago
|
t.deepEqual(messages.errors, [], 'no error returned');
|
||
|
t.deepEqual(messages.warnings, [], 'no warnings returned');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.tests.invalid_sources = function(test, common) {
|
||
|
test('geonames source', function(t) {
|
||
|
var req = {
|
||
|
query: {
|
||
9 years ago
|
sources: 'notasource'
|
||
9 years ago
|
},
|
||
|
clean: { }
|
||
9 years ago
|
};
|
||
9 years ago
|
var expected_messages = {
|
||
|
errors: [
|
||
9 years ago
|
'\'notasource\' is an invalid sources parameter. ' +
|
||
9 years ago
|
'Valid options: osm,oa,gn,wof,openstreetmap,openaddresses,geonames,whosonfirst'
|
||
9 years ago
|
],
|
||
|
warnings: []
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
var messages = sanitize(req.query, req.clean);
|
||
9 years ago
|
|
||
9 years ago
|
t.deepEqual(messages, expected_messages, 'error with message returned');
|
||
9 years ago
|
t.equal(req.clean.sources, undefined, 'clean.sources should remain empty');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.all = function (tape, common) {
|
||
|
function test(name, testFunction) {
|
||
9 years ago
|
return tape('SANTIZE _sources ' + name, testFunction);
|
||
9 years ago
|
}
|
||
|
|
||
|
for( var testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|