From 94eaafd39a7d30cf65a87fea8caa4ea81f99c58e Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Mon, 10 Oct 2016 15:12:04 -0400 Subject: [PATCH] setup labelGenerator to have a default --- middleware/assignLabels.js | 2 +- test/unit/middleware/assignLabels.js | 43 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/middleware/assignLabels.js b/middleware/assignLabels.js index 1b2aa109..8ee52acc 100644 --- a/middleware/assignLabels.js +++ b/middleware/assignLabels.js @@ -1,6 +1,6 @@ function setup(labelGenerator) { function middleware(req, res, next) { - return assignLabel(req, res, next, labelGenerator); + return assignLabel(req, res, next, labelGenerator || require('pelias-labels')); } return middleware; diff --git a/test/unit/middleware/assignLabels.js b/test/unit/middleware/assignLabels.js index 34d689c3..305f99f6 100644 --- a/test/unit/middleware/assignLabels.js +++ b/test/unit/middleware/assignLabels.js @@ -1,3 +1,5 @@ +var proxyquire = require('proxyquire').noCallThru(); + module.exports.tests = {}; module.exports.tests.serialization = function(test, common) { @@ -93,6 +95,47 @@ module.exports.tests.serialization = function(test, common) { }); + test('no explicit labelGenerator supplied should use pelias-labels module', function(t) { + var assignLabels = proxyquire('../../../middleware/assignLabels', { + 'pelias-labels': function(properties) { + if (properties.id === 1) { + return 'label 1'; + } + } + })(); + + var input = { + body: { + features: [ + { + properties: { + id: 1 + } + } + ] + } + }; + + var expected = { + body: { + features: [ + { + properties: { + id: 1, + label: 'label 1' + } + } + ] + } + }; + + assignLabels({}, input, function () { + t.deepEqual(input, expected); + t.end(); + }); + + }); + }; module.exports.all = function (tape, common) {