Browse Source

Merge pull request #574 from pelias/short-sources-gid

Short sources gid
pull/583/head
Julian Simioni 9 years ago committed by GitHub
parent
commit
1b175fe31a
  1. 8
      sanitiser/_ids.js
  2. 35
      test/unit/sanitiser/_ids.js

8
sanitiser/_ids.js

@ -34,9 +34,9 @@ function sanitizeId(rawId, messages) {
messages.errors.push( formatError(rawId) );
return;
}
if (!_.includes(type_mapping.sources, source)) {
messages.errors.push( targetError(source, type_mapping.sources) );
var valid_values = Object.keys(type_mapping.source_mapping);
if (!_.includes(valid_values, source)) {
messages.errors.push( targetError(source, valid_values) );
return;
}
@ -46,7 +46,7 @@ function sanitizeId(rawId, messages) {
}
return {
source: source,
source: type_mapping.source_mapping[source][0],
layer: layer,
id: id,
};

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) {
var raw = { ids: 'invalidsource:venue:23' };
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);
@ -107,6 +108,22 @@ module.exports.tests.valid_ids = function(test, common) {
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) {
var raw = { ids: 'openstreetmap:venue:node:500' };
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.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) {

Loading…
Cancel
Save