Browse Source

Expect an array of types from _ids sanitiser

This doesn't have any effect by itself but allows for the 3-part gid
sanitiser to possibly return multiple types (i.e. in the case of
osm:venue:1000)
pull/292/head
Julian Simioni 9 years ago
parent
commit
2505e92a62
  1. 2
      controller/place.js
  2. 2
      sanitiser/_ids.js
  3. 8
      test/unit/controller/place.js
  4. 2
      test/unit/mock/backend.js
  5. 8
      test/unit/sanitiser/_ids.js
  6. 2
      test/unit/sanitiser/place.js

2
controller/place.js

@ -16,7 +16,7 @@ function setup( backend ){
var query = req.clean.ids.map( function(id) { var query = req.clean.ids.map( function(id) {
return { return {
_index: 'pelias', _index: 'pelias',
_type: id.type, type: id.types,
_id: id.id _id: id.id
}; };
}); });

2
sanitiser/_ids.js

@ -31,7 +31,7 @@ function sanitizeId(rawId, messages) {
else { else {
return { return {
id: id, id: id,
type: type types: [type]
}; };
} }
} }

8
test/unit/controller/place.js

@ -41,7 +41,7 @@ module.exports.tests.functional_success = function(test, common) {
test('functional success', function(t) { test('functional success', function(t) {
var backend = mockBackend( 'client/mget/ok/1', function( cmd ){ var backend = mockBackend( 'client/mget/ok/1', function( cmd ){
t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', _type: 'a' } ] } }, 'correct backend command'); t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', type: [ 'a' ] } ] } }, 'correct backend command');
}); });
var controller = setup( backend ); var controller = setup( backend );
var res = { var res = {
@ -57,7 +57,7 @@ module.exports.tests.functional_success = function(test, common) {
t.deepEqual(json.features, expected, 'values correctly mapped'); t.deepEqual(json.features, expected, 'values correctly mapped');
} }
}; };
var req = { clean: { ids: [ {'id' : 123, 'type': 'a' } ] }, errors: [], warnings: [] }; var req = { clean: { ids: [ {'id' : 123, types: [ 'a' ] } ] }, errors: [], warnings: [] };
var next = function next() { var next = function next() {
t.equal(req.errors.length, 0, 'next was called without error'); t.equal(req.errors.length, 0, 'next was called without error');
t.end(); t.end();
@ -70,10 +70,10 @@ module.exports.tests.functional_success = function(test, common) {
module.exports.tests.functional_failure = function(test, common) { module.exports.tests.functional_failure = function(test, common) {
test('functional failure', function(t) { test('functional failure', function(t) {
var backend = mockBackend( 'client/mget/fail/1', function( cmd ){ var backend = mockBackend( 'client/mget/fail/1', function( cmd ){
t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', _type: 'b' } ] } }, 'correct backend command'); t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', type: [ 'b' ] } ] } }, 'correct backend command');
}); });
var controller = setup( backend ); var controller = setup( backend );
var req = { clean: { ids: [ {'id' : 123, 'type': 'b' } ] }, errors: [], warnings: [] }; var req = { clean: { ids: [ {'id' : 123, types: [ 'b' ] } ] }, errors: [], warnings: [] };
var next = function( message ){ var next = function( message ){
t.equal(req.errors[0],'a backend error occurred','error passed to errorHandler'); t.equal(req.errors[0],'a backend error occurred','error passed to errorHandler');
t.end(); t.end();

2
test/unit/mock/backend.js

@ -94,4 +94,4 @@ function searchEnvelope( options ){
return { hits: { total: options.length, hits: options } }; return { hits: { total: options.length, hits: options } };
} }
module.exports = setup; module.exports = setup;

8
test/unit/sanitiser/_ids.js

@ -90,7 +90,7 @@ module.exports.tests.valid_ids = function(test, common) {
test('ids: valid input', function(t) { test('ids: valid input', function(t) {
inputs.valid.forEach( function( input ){ inputs.valid.forEach( function( input ){
var input_parts = input.split(delimiter); var input_parts = input.split(delimiter);
var expected_clean = { ids: [ { id: input_parts[1], type: input_parts[0] } ]}; var expected_clean = { ids: [ { id: input_parts[1], types: [ input_parts[0] ]} ]};
var raw = { ids: input }; var raw = { ids: input };
var clean = {}; var clean = {};
@ -111,7 +111,7 @@ module.exports.tests.valid_ids = function(test, common) {
// construct the expected id and type for each valid input // construct the expected id and type for each valid input
inputs.valid.forEach( function( input ){ inputs.valid.forEach( function( input ){
var input_parts = input.split(delimiter); var input_parts = input.split(delimiter);
expected_clean.ids.push({ id: input_parts[1], type: input_parts[0] }); expected_clean.ids.push({ id: input_parts[1], types: [ input_parts[0] ]});
}); });
var messages = sanitize( raw, clean ); var messages = sanitize( raw, clean );
@ -138,7 +138,7 @@ module.exports.tests.array_of_ids = function(test, common) {
module.exports.tests.multiple_ids = function(test, common) { module.exports.tests.multiple_ids = function(test, common) {
test('duplicate ids', function(t) { test('duplicate ids', function(t) {
var expected_clean = { ids: [ { id: '1', type: 'geoname' }, { id: '2', type: 'osmnode' } ] }; var expected_clean = { ids: [ { id: '1', types: [ 'geoname' ] }, { id: '2', types: [ 'osmnode' ] } ] };
var raw = { ids: 'geoname:1,osmnode:2' }; var raw = { ids: 'geoname:1,osmnode:2' };
var clean = {}; var clean = {};
@ -153,7 +153,7 @@ module.exports.tests.multiple_ids = function(test, common) {
module.exports.tests.de_dupe = function(test, common) { module.exports.tests.de_dupe = function(test, common) {
test('duplicate ids', function(t) { test('duplicate ids', function(t) {
var expected_clean = { ids: [ { id: '1', type: 'geoname' }, { id: '2', type: 'osmnode' } ]}; var expected_clean = { ids: [ { id: '1', types: [ 'geoname' ] }, { id: '2', types: [ 'osmnode' ] } ] };
var raw = { ids: 'geoname:1,osmnode:2,geoname:1' }; var raw = { ids: 'geoname:1,osmnode:2,geoname:1' };
var clean = {}; var clean = {};

2
test/unit/sanitiser/place.js

@ -1,7 +1,7 @@
var place = require('../../../sanitiser/place'), var place = require('../../../sanitiser/place'),
sanitize = place.sanitize, sanitize = place.sanitize,
middleware = place.middleware, middleware = place.middleware,
defaultClean = { ids: [ { id: '123', type: 'geoname' } ], private: false }; defaultClean = { ids: [ { id: '123', types: [ 'geoname' ] } ], private: false };
// these are the default values you would expect when no input params are specified. // these are the default values you would expect when no input params are specified.
module.exports.tests = {}; module.exports.tests = {};

Loading…
Cancel
Save