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 1 commit
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
10 changes: 7 additions & 3 deletions sanitiser/_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ 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;
}

if (!_.includes(type_mapping.layers, layer)) {
messages.errors.push( targetError(layer, type_mapping.layers) );
return;
}
//converts the shortened source names to the full name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could remove the if statement here, since the source_mapping supports either the short or long name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice reason to do that is it keeps more knowledge of what the "real" source name is in the type_mapping file, rather than here

if(source !== type_mapping.source_mapping[source]){
source = type_mapping.source_mapping[source][0];
}

return {
source: source,
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