Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short sources gid #574

Merged
merged 2 commits into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sanitiser/_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -46,7 +46,7 @@ function sanitizeId(rawId, messages) {
}

return {
source: source,
source: type_mapping.source_mapping[source][0],
layer: layer,
id: id,
};
Expand Down
35 changes: 34 additions & 1 deletion test/unit/sanitiser/_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 = {};
Expand All @@ -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) {
Expand Down