From 69a820fae0a9ae3eb02bce431f44d7ffcb7f503a Mon Sep 17 00:00:00 2001 From: missinglink Date: Thu, 28 Sep 2017 14:30:37 +0200 Subject: [PATCH] feat(coarse_reverse): ignore empty abbr properties from PIP service --- controller/coarse_reverse.js | 2 +- test/unit/controller/coarse_reverse.js | 60 ++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/controller/coarse_reverse.js b/controller/coarse_reverse.js index cae79a78..2c7b370b 100644 --- a/controller/coarse_reverse.js +++ b/controller/coarse_reverse.js @@ -68,7 +68,7 @@ function synthesizeDoc(results) { // assign the administrative hierarchy _.keys(results).forEach((layer) => { - doc.addParent(layer, results[layer][0].name, results[layer][0].id.toString(), results[layer][0].abbr); + doc.addParent(layer, results[layer][0].name, results[layer][0].id.toString(), results[layer][0].abbr || undefined); }); // set centroid if available diff --git a/test/unit/controller/coarse_reverse.js b/test/unit/controller/coarse_reverse.js index d4e357cb..f9e3709f 100644 --- a/test/unit/controller/coarse_reverse.js +++ b/test/unit/controller/coarse_reverse.js @@ -911,6 +911,66 @@ module.exports.tests.failure_conditions = (test, common) => { t.end(); }); + + test('service returns 0 length abbr', (t) => { + t.plan(4); + + const service = (req, callback) => { + t.deepEquals(req, { clean: { layers: ['neighbourhood'] } } ); + + const results = { + neighbourhood: [ + { id: 20, name: 'Example', abbr: '' } + ] + }; + + callback(undefined, results); + }; + + const logger = require('pelias-mock-logger')(); + + const controller = proxyquire('../../../controller/coarse_reverse', { + 'pelias-logger': logger + })(service, _.constant(true)); + + const req = { + clean: { + layers: ['neighbourhood'] + } + }; + + const res = { }; + + // verify that next was called + const next = () => { + t.pass('next() was called'); + }; + + controller(req, res, next); + + const expected = { + meta: {}, + data: [{ + name: { default: 'Example' }, + phrase: { default: 'Example' }, + parent: { + neighbourhood: [ 'Example' ], + neighbourhood_id: [ '20' ], + neighbourhood_a: [ null ] + }, + source: 'whosonfirst', + layer: 'neighbourhood', + source_id: '20', + _id: '20', + _type: 'neighbourhood' + }] + }; + + t.deepEquals(res, expected); + t.notOk(logger.hasErrorMessages()); + t.end(); + + }); }; module.exports.all = (tape, common) => {