Add test to check if NULL category count values properly

This commit is contained in:
Daniel García Aubert 2017-01-16 17:00:28 +01:00
parent 2598595e42
commit f5f0601e53

View File

@ -13,8 +13,11 @@ describe('aggregations', function() {
}
});
function aggregationOperationMapConfig(operation) {
return {
function aggregationOperationMapConfig(operation, column, aggregationColumn) {
column = column || 'adm0name';
aggregationColumn = aggregationColumn || 'pop_max';
var mapConfig = {
version: '1.5.0',
layers: [
{
@ -23,20 +26,22 @@ describe('aggregations', function() {
sql: 'select * from populated_places_simple_reduced',
cartocss: '#layer0 { marker-fill: red; marker-width: 10; }',
cartocss_version: '2.0.1',
widgets: {
adm0name: {
type: 'aggregation',
options: {
column: 'adm0name',
aggregation: operation,
aggregationColumn: 'pop_max'
}
}
}
widgets: {}
}
}
]
};
mapConfig.layers[0].options.widgets[column] = {
type: 'aggregation',
options: {
column: column,
aggregation: operation,
aggregationColumn: aggregationColumn
}
};
return mapConfig;
}
var operations = ['count', 'sum', 'avg', 'max', 'min'];
@ -56,4 +61,26 @@ describe('aggregations', function() {
});
});
});
it('should count NULL category', function (done) {
this.testClient = new TestClient(aggregationOperationMapConfig('count', 'namepar'));
this.testClient.getDataview('namepar', { own_filter: 0 }, function (err, aggregation) {
assert.ifError(err);
assert.ok(aggregation);
assert.equal(aggregation.type, 'aggregation');
assert.ok(aggregation.categories);
var hasNullCategory = false;
aggregation.categories.forEach(function (category) {
if (category.category === null) {
assert.ok(category.value > 0);
hasNullCategory = true;
}
});
assert.ok(hasNullCategory, 'there is no category NULL');
done();
});
});
});