From 2505e92a6211fd5ceffcb75a9c4b06c52a562c39 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 21 Sep 2015 18:22:24 -0400 Subject: [PATCH] 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) --- controller/place.js | 2 +- sanitiser/_ids.js | 2 +- test/unit/controller/place.js | 8 ++++---- test/unit/mock/backend.js | 2 +- test/unit/sanitiser/_ids.js | 8 ++++---- test/unit/sanitiser/place.js | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/controller/place.js b/controller/place.js index 8622f234..42e7c626 100644 --- a/controller/place.js +++ b/controller/place.js @@ -16,7 +16,7 @@ function setup( backend ){ var query = req.clean.ids.map( function(id) { return { _index: 'pelias', - _type: id.type, + type: id.types, _id: id.id }; }); diff --git a/sanitiser/_ids.js b/sanitiser/_ids.js index b45f0d1c..46effa41 100644 --- a/sanitiser/_ids.js +++ b/sanitiser/_ids.js @@ -31,7 +31,7 @@ function sanitizeId(rawId, messages) { else { return { id: id, - type: type + types: [type] }; } } diff --git a/test/unit/controller/place.js b/test/unit/controller/place.js index 755ac1b9..20455e3a 100644 --- a/test/unit/controller/place.js +++ b/test/unit/controller/place.js @@ -41,7 +41,7 @@ module.exports.tests.functional_success = function(test, common) { test('functional success', function(t) { 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 res = { @@ -57,7 +57,7 @@ module.exports.tests.functional_success = function(test, common) { 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() { t.equal(req.errors.length, 0, 'next was called without error'); t.end(); @@ -70,10 +70,10 @@ module.exports.tests.functional_success = function(test, common) { module.exports.tests.functional_failure = function(test, common) { test('functional failure', function(t) { 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 req = { clean: { ids: [ {'id' : 123, 'type': 'b' } ] }, errors: [], warnings: [] }; + var req = { clean: { ids: [ {'id' : 123, types: [ 'b' ] } ] }, errors: [], warnings: [] }; var next = function( message ){ t.equal(req.errors[0],'a backend error occurred','error passed to errorHandler'); t.end(); diff --git a/test/unit/mock/backend.js b/test/unit/mock/backend.js index 201ab7b5..7d0eb8d7 100644 --- a/test/unit/mock/backend.js +++ b/test/unit/mock/backend.js @@ -94,4 +94,4 @@ function searchEnvelope( options ){ return { hits: { total: options.length, hits: options } }; } -module.exports = setup; \ No newline at end of file +module.exports = setup; diff --git a/test/unit/sanitiser/_ids.js b/test/unit/sanitiser/_ids.js index 26445018..3be9183b 100644 --- a/test/unit/sanitiser/_ids.js +++ b/test/unit/sanitiser/_ids.js @@ -90,7 +90,7 @@ module.exports.tests.valid_ids = function(test, common) { test('ids: valid input', function(t) { inputs.valid.forEach( function( input ){ 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 clean = {}; @@ -111,7 +111,7 @@ module.exports.tests.valid_ids = function(test, common) { // construct the expected id and type for each valid input inputs.valid.forEach( function( input ){ 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 ); @@ -138,7 +138,7 @@ module.exports.tests.array_of_ids = function(test, common) { module.exports.tests.multiple_ids = function(test, common) { 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 clean = {}; @@ -153,7 +153,7 @@ module.exports.tests.multiple_ids = function(test, common) { module.exports.tests.de_dupe = function(test, common) { 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 clean = {}; diff --git a/test/unit/sanitiser/place.js b/test/unit/sanitiser/place.js index c3cd81cf..26042c5e 100644 --- a/test/unit/sanitiser/place.js +++ b/test/unit/sanitiser/place.js @@ -1,7 +1,7 @@ var place = require('../../../sanitiser/place'), sanitize = place.sanitize, 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. module.exports.tests = {};