If we have the stats FF disbabled return empty array instead of null

But we keep checking for elements in the returned object because
we don't want to include the stats property if the FF is disabled
This commit is contained in:
Mario de Frutos 2017-05-30 10:47:47 +02:00
parent d471905358
commit 440953b1cd
3 changed files with 26 additions and 5 deletions

View File

@ -11,6 +11,6 @@ StatsBackend.prototype.getStats = function(mapConfig, dbConnection, callback) {
if (layerStatsEnabled) {
layerStats().getStats(mapConfig, dbConnection, callback);
} else {
return callback(null, null);
return callback(null, []);
}
};

View File

@ -368,7 +368,7 @@ function(req, res, mapconfig, layergroup, analysesResults, callback) {
if (err) {
return next(err);
}
if (layersStats) {
if (layersStats.length > 0) {
layergroup.metadata.layers.forEach(function (layer, index) {
layer.meta.stats = layersStats[index];
});

View File

@ -5,14 +5,11 @@ var TestClient = require('../../support/test-client');
describe('Create mapnik layergroup', function() {
before(function() {
this.layerMetadataConfig = global.environment.enabledFeatures.layerMetadata;
this.layerStatsConfig = global.environment.enabledFeatures.layerStats;
global.environment.enabledFeatures.layerMetadata = true;
global.environment.enabledFeatures.layerStats = true;
});
after(function() {
global.environment.enabledFeatures.layerMetadata = this.layerMetadataConfig;
global.environment.enabledFeatures.layerStats = this.layerStatsConfig;
});
@ -255,4 +252,28 @@ describe('Create mapnik layergroup', function() {
testClient.drain(done);
});
});
it('should not include the stats part if the FF is disabled', function(done) {
global.environment.enabledFeatures.layerStats = false;
var testClient = new TestClient({
version: '1.4.0',
layers: [
httpLayer,
mapnikLayer1,
httpLayer
]
});
testClient.getLayergroup(function(err, layergroup) {
assert.ok(!err);
assert.equal(layergroup.metadata.layers[0].id, typeLayerId('http', 0));
assert.equal(layergroup.metadata.layers[0].type, 'http');
assert.equal(layergroup.metadata.layers[1].id, mapnikBasicLayerId(0));
assert.equal(layergroup.metadata.layers[1].type, 'mapnik');
assert.ok(!layergroup.metadata.layers[1].meta.hasOwnProperty('stats'));
assert.equal(layergroup.metadata.layers[2].id, typeLayerId('http', 1));
assert.equal(layergroup.metadata.layers[2].type, 'http');
testClient.drain(done);
});
});
});