Browse Source

Allow shortened names of sources to be used in gid

pull/574/head
Alec Vulfson 8 years ago
parent
commit
4dc0f90088
  1. 10
      sanitiser/_ids.js
  2. 35
      test/unit/sanitiser/_ids.js

10
sanitiser/_ids.js

@ -34,9 +34,9 @@ function sanitizeId(rawId, messages) {
messages.errors.push( formatError(rawId) ); messages.errors.push( formatError(rawId) );
return; return;
} }
var valid_values = Object.keys(type_mapping.source_mapping);
if (!_.includes(type_mapping.sources, source)) { if (!_.includes(valid_values, source)) {
messages.errors.push( targetError(source, type_mapping.sources) ); messages.errors.push( targetError(source, valid_values) );
return; return;
} }
@ -44,6 +44,10 @@ function sanitizeId(rawId, messages) {
messages.errors.push( targetError(layer, type_mapping.layers) ); messages.errors.push( targetError(layer, type_mapping.layers) );
return; return;
} }
//converts the shortened source names to the full name
if(source !== type_mapping.source_mapping[source]){
source = type_mapping.source_mapping[source][0];
}
return { return {
source: source, source: source,

35
test/unit/sanitiser/_ids.js

@ -69,7 +69,8 @@ module.exports.tests.invalid_ids = function(test, common) {
test('invalid id: source name invalid', function(t) { test('invalid id: source name invalid', function(t) {
var raw = { ids: 'invalidsource:venue:23' }; var raw = { ids: 'invalidsource:venue:23' };
var clean = {}; var clean = {};
var expected_error = 'invalidsource is invalid. It must be one of these values - [' + type_mapping.sources.join(', ') + ']'; var expected_error = 'invalidsource is invalid. It must be one of these values - [' +
Object.keys(type_mapping.source_mapping).join(', ') + ']';
var messages = sanitize(raw, clean); var messages = sanitize(raw, clean);
@ -107,6 +108,22 @@ module.exports.tests.valid_ids = function(test, common) {
t.end(); t.end();
}); });
test('ids: valid short input (openaddresses)', function(t) {
var raw = { ids: 'oa:address:20' };
var clean = {};
var messages = sanitize( raw, clean );
var expected_ids = [{
source: 'openaddresses',
layer: 'address',
id: '20',
}];
t.deepEqual( messages.errors, [], ' no errors');
t.deepEqual( clean.ids, expected_ids, 'single type value returned');
t.end();
});
test('ids: valid input (osm)', function(t) { test('ids: valid input (osm)', function(t) {
var raw = { ids: 'openstreetmap:venue:node:500' }; var raw = { ids: 'openstreetmap:venue:node:500' };
var clean = {}; var clean = {};
@ -122,6 +139,22 @@ module.exports.tests.valid_ids = function(test, common) {
t.deepEqual( clean.ids, expected_ids, 'osm has node: or way: in id field'); t.deepEqual( clean.ids, expected_ids, 'osm has node: or way: in id field');
t.end(); t.end();
}); });
test('ids: valid short input (osm)', function(t) {
var raw = { ids: 'osm:venue:node:500' };
var clean = {};
var expected_ids = [{
source: 'openstreetmap',
layer: 'venue',
id: 'node:500',
}];
var messages = sanitize( raw, clean );
t.deepEqual( messages.errors, [], ' no errors');
t.deepEqual( clean.ids, expected_ids, 'osm has node: or way: in id field');
t.end();
});
}; };
module.exports.tests.multiple_ids = function(test, common) { module.exports.tests.multiple_ids = function(test, common) {

Loading…
Cancel
Save