Browse Source

setup labelGenerator to have a default

pull/680/head
Stephen Hess 8 years ago
parent
commit
94eaafd39a
  1. 2
      middleware/assignLabels.js
  2. 43
      test/unit/middleware/assignLabels.js

2
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;

43
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) {

Loading…
Cancel
Save