From 561be2e5e80de4ff11c092f60204153b0a818c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 27 Feb 2019 12:43:26 +0100 Subject: [PATCH] Add tests --- test/acceptance/cluster.js | 116 +++++++++++++++++++++++++++++++----- test/support/test-client.js | 6 +- 2 files changed, 105 insertions(+), 17 deletions(-) diff --git a/test/acceptance/cluster.js b/test/acceptance/cluster.js index 0cb3f1a7..c62e87c8 100644 --- a/test/acceptance/cluster.js +++ b/test/acceptance/cluster.js @@ -2,7 +2,7 @@ require('../support/test_helper'); -// const assert = require('../support/assert'); +const assert = require('../support/assert'); const TestClient = require('../support/test-client'); const POINTS_SQL_1 = ` @@ -18,7 +18,9 @@ const defaultLayers = [{ type: 'cartodb', options: { sql: POINTS_SQL_1, - aggregation: true + aggregation: { + threshold: 1 + } } }]; @@ -30,20 +32,106 @@ function createVectorMapConfig (layers = defaultLayers) { } describe('cluster', function () { - it.only('should get aggregated features of an aggregated map', function (done) { - const mapConfig = createVectorMapConfig(); - const testClient = new TestClient(mapConfig); - const clusterId = 1; - const layerId = 0; - const params = {}; - - testClient.getClusterFeatures(clusterId, layerId, params, (err, body) => { - if (err) { - return done(err); + describe('resolution = 1', function () { + const suite = [ + { + cartodb_id: 1, + expected: [ { cartodb_id: 1, value: -3 } ] + }, + { + cartodb_id: 2, + expected: [ { cartodb_id: 2, value: -2 } ] + }, + { + cartodb_id: 3, + expected: [ { cartodb_id: 3, value: -1 } ] + }, + { + cartodb_id: 4, + expected: [ { cartodb_id: 4, value: 0 } ] + }, + { + cartodb_id: 5, + expected: [ { cartodb_id: 5, value: 1 } ] + }, + { + cartodb_id: 6, + expected: [ { cartodb_id: 6, value: 2 } ] } + ]; - console.log('>>>>>>>>>>>>', body.rows); - testClient.drain(done); + suite.forEach(({ cartodb_id, expected }) => { + it(`should get just one disaggregated feature: cartodb_id = ${cartodb_id}`, function (done) { + const mapConfig = createVectorMapConfig(); + const testClient = new TestClient(mapConfig); + const zoom = 0; + const clusterId = cartodb_id; + const layerId = 0; + const params = {}; + + testClient.getClusterFeatures(zoom, clusterId, layerId, params, (err, body) => { + if (err) { + return done(err); + } + + assert.deepStrictEqual(body.rows, expected); + testClient.drain(done); + }); + }); + }); + }); + + describe('resolution = 50', function () { + const suite = [ + { + cartodb_id: 1, + resolution: 50, + expected: [ + { cartodb_id: 1, value: -3 }, + { cartodb_id: 2, value: -2 }, + { cartodb_id: 3, value: -1 }, + { cartodb_id: 4, value: 0 }, + ] + }, + { + cartodb_id: 5, + resolution: 50, + expected: [ + { cartodb_id: 5, value: 1 }, + { cartodb_id: 6, value: 2 }, + { cartodb_id: 7, value: 3 } + ] + } + ]; + + suite.forEach(({ cartodb_id, resolution, expected }) => { + it(`should get just one disaggregated feature: cartodb_id = ${cartodb_id}`, function (done) { + const mapConfig = createVectorMapConfig([{ + type: 'cartodb', + options: { + sql: POINTS_SQL_1, + aggregation: { + threshold: 1, + resolution: resolution + } + } + }]); + + const testClient = new TestClient(mapConfig); + const zoom = 0; + const clusterId = cartodb_id; + const layerId = 0; + const params = {}; + + testClient.getClusterFeatures(zoom, clusterId, layerId, params, (err, body) => { + if (err) { + return done(err); + } + + assert.deepStrictEqual(body.rows, expected); + testClient.drain(done); + }); + }); }); }); }); diff --git a/test/support/test-client.js b/test/support/test-client.js index 9eb340cb..b1e4a211 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -620,7 +620,7 @@ TestClient.prototype.getFeatureAttributes = function(featureId, layerId, params, ); }; -TestClient.prototype.getClusterFeatures = function(clusterId, layerId, params, callback) { +TestClient.prototype.getClusterFeatures = function (zoom, clusterId, layerId, params, callback) { var self = this; if (!callback) { @@ -685,12 +685,12 @@ TestClient.prototype.getClusterFeatures = function(clusterId, layerId, params, c } ); }, - function getCLusterFeatures(err, layergroupId) { + function getCLusterFeatures (err, layergroupId) { assert.ifError(err); var next = this; - url = '/api/v1/map/' + layergroupId + '/' + layerId + '/cluster/' + clusterId; + url = '/api/v1/map/' + layergroupId + '/' + layerId + '/' + zoom + '/cluster/' + clusterId; assert.response(self.server, {