2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../../support/test-helper');
|
2016-02-05 20:32:38 +08:00
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('aggregation widgets', function () {
|
|
|
|
var aggregationMapConfig = {
|
2016-02-05 20:32:38 +08:00
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from populated_places_simple_reduced',
|
|
|
|
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
widgets: {
|
|
|
|
country_places_count: {
|
|
|
|
type: 'aggregation',
|
|
|
|
options: {
|
|
|
|
column: 'adm0_a3',
|
|
|
|
aggregation: 'count'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose an aggregation', function (done) {
|
2016-02-05 20:32:38 +08:00
|
|
|
var testClient = new TestClient(aggregationMapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getWidget('country_places_count', { own_filter: 0 }, function (err, res) {
|
2016-02-05 20:32:38 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var aggregation = JSON.parse(res.body);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(aggregation.categories.length, 6);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(aggregation.categories[0], { value: 769, category: 'USA', agg: false });
|
2016-02-05 20:32:38 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('filters', function () {
|
2016-02-05 20:32:38 +08:00
|
|
|
describe('category', function () {
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a filtered aggregation', function (done) {
|
2016-02-05 20:32:38 +08:00
|
|
|
var params = {
|
|
|
|
filters: {
|
|
|
|
layers: [
|
2019-10-22 01:07:24 +08:00
|
|
|
{ country_places_count: { accept: ['CAN'] } }
|
2016-02-05 20:32:38 +08:00
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var testClient = new TestClient(aggregationMapConfig);
|
|
|
|
testClient.getWidget('country_places_count', params, function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var aggregation = JSON.parse(res.body);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(aggregation.categories.length, 1);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(aggregation.categories[0], { value: 256, category: 'CAN', agg: false });
|
2016-02-05 20:32:38 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|