From 7df1a19da4ec2bdaaf3d0923799ffe7694af5366 Mon Sep 17 00:00:00 2001 From: IagoLast Date: Tue, 5 Jun 2018 08:58:44 +0200 Subject: [PATCH] Add test for multiple-layer date wrap --- test/acceptance/date-wrapping.spec.js | 122 +++++++++++++++---------- test/fixtures/test_mapconfigFactory.js | 75 +++++++-------- 2 files changed, 112 insertions(+), 85 deletions(-) diff --git a/test/acceptance/date-wrapping.spec.js b/test/acceptance/date-wrapping.spec.js index 5049fd51..fed6278e 100644 --- a/test/acceptance/date-wrapping.spec.js +++ b/test/acceptance/date-wrapping.spec.js @@ -6,69 +6,93 @@ const mapConfigFactory = require('../fixtures/test_mapconfigFactory'); describe('date-wrapping', () => { let testClient; - describe('when a map instantiation has the "dates_as_numbers" option enabled', () => { - beforeEach(() => { - const mapConfig = mapConfigFactory.getVectorMapConfig({ dates_as_numbers: true }); - testClient = new TestClient(mapConfig); + describe('when a map instantiation has one single layer', () => { + describe('and the layer has the "dates_as_numbers" option enabled', () => { + beforeEach(() => { + const mapConfig = mapConfigFactory.getVectorMapConfig({ dates_as_numbers: true }); + testClient = new TestClient(mapConfig); + }); + + afterEach(done => testClient.drain(done)); + + it('should return date columns casted as numbers', done => { + + testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => { + const expected = [ + { + type: 'Feature', + id: 1, + geometry: { type: 'Point', coordinates: [0, 0] }, + properties: { _cdb_feature_count: 1, cartodb_id: 0, date: 1527810000 } + }, + { + type: 'Feature', + id: 2, + geometry: { type: 'Point', coordinates: [0, 0] }, + properties: { _cdb_feature_count: 1, cartodb_id: 1, date: 1527900000 } + } + ]; + const actual = JSON.parse(mvt.toGeoJSONSync(0)).features; + + assert.deepEqual(actual, expected); + done(); + }); + }); }); - afterEach(done => testClient.drain(done)); + describe('and the layer has the "dates_as_numbers" option disabled', () => { + beforeEach(() => { + const mapConfig = mapConfigFactory.getVectorMapConfig({ dates_as_numbers: false }); + testClient = new TestClient(mapConfig); + }); - it('should return date columns casted as numbers', done => { + afterEach(done => testClient.drain(done)); - testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => { - const expected = [ - { - type: 'Feature', - id: 1, - geometry: { type: 'Point', coordinates: [0, 0] }, - properties: { _cdb_feature_count: 1, cartodb_id: 0, date: 1527810000 } - }, - { - type: 'Feature', - id: 2, - geometry: { type: 'Point', coordinates: [0, 0] }, - properties: { _cdb_feature_count: 1, cartodb_id: 1, date: 1527900000 } - } - ]; - const actual = JSON.parse(mvt.toGeoJSONSync(0)).features; + it('should return date columns as dates', done => { - assert.deepEqual(actual, expected); - done(); + testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => { + const expected = [ + { + type: 'Feature', + id: 1, + geometry: { type: 'Point', coordinates: [0, 0] }, + properties: { _cdb_feature_count: 1, cartodb_id: 0 } + }, + { + type: 'Feature', + id: 2, + geometry: { type: 'Point', coordinates: [0, 0] }, + properties: { _cdb_feature_count: 1, cartodb_id: 1 } + } + ]; + const actual = JSON.parse(mvt.toGeoJSONSync(0)).features; + + assert.deepEqual(actual, expected); + done(); + }); }); }); }); - describe('when a map instantiation has the "dates_as_numbers" option disabled', () => { + + describe('when a map instantiation has multiple layers', () => { beforeEach(() => { - const mapConfig = mapConfigFactory.getVectorMapConfig({ dates_as_numbers: false }); + const mapConfig = mapConfigFactory.getVectorMapConfig({ numberOfLayers: 2 }); testClient = new TestClient(mapConfig); }); + describe('and both layers have the "dates_as_numbers" option enabled', () => { + // TODO: Pending test + it('should return dates as numbers for every layer'); + }); - afterEach(done => testClient.drain(done)); + describe('and only one layers has the "dates_as_numbers" option enabled', () => { + // TODO: Pending test + it('should return dates as numbers only for the layer with the "dates_as_numbers" flag enabled'); + }); - it('should return date columns as dates', done => { - - testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => { - const expected = [ - { - type: 'Feature', - id: 1, - geometry: { type: 'Point', coordinates: [0, 0] }, - properties: { _cdb_feature_count: 1, cartodb_id: 0 } - }, - { - type: 'Feature', - id: 2, - geometry: { type: 'Point', coordinates: [0, 0] }, - properties: { _cdb_feature_count: 1, cartodb_id: 1 } - } - ]; - const actual = JSON.parse(mvt.toGeoJSONSync(0)).features; - - assert.deepEqual(actual, expected); - done(); - }); + describe('and none of the layers has the "dates_as_numbers" option enabled', () => { + // TODO: Pending test + it('should return dates as dates for both layers'); }); }); }); \ No newline at end of file diff --git a/test/fixtures/test_mapconfigFactory.js b/test/fixtures/test_mapconfigFactory.js index 54643475..0a46de5f 100644 --- a/test/fixtures/test_mapconfigFactory.js +++ b/test/fixtures/test_mapconfigFactory.js @@ -4,44 +4,47 @@ function getVectorMapConfig(opts) { buffersize: { mvt: 1 }, - layers: [ - { - type: 'mapnik', - options: { - sql: ` - SELECT - (DATE '2018-06-01' + x) as date, - x as cartodb_id, - st_makepoint(x * 10, x * 10) as the_geom, - st_makepoint(x * 10, x * 10) as the_geom_webmercator - FROM - generate_series(0, 1) x`, - aggregation: { - columns: {}, - dimensions: { - date: 'date' - }, - placement: 'centroid', - resolution: 1, - threshold: 1 - }, - dates_as_numbers: opts.dates_as_numbers, - metadata: { - geometryType: true, - columnStats: { - topCategories: 32768, - includeNulls: true - }, - sample: { - num_rows: 1000, - include_columns: [ - 'date' - ] - } - } + layers: Array(opts.numberOfLayers ||  1).map(() => _generateLayerConfig(opts)); + }; +} + + +function _generateLayerConfig(opts) { + return { + type: 'mapnik', + options: { + sql: ` + SELECT + (DATE '2018-06-01' + x) as date, + x as cartodb_id, + st_makepoint(x * 10, x * 10) as the_geom, + st_makepoint(x * 10, x * 10) as the_geom_webmercator + FROM + generate_series(0, 1) x`, + aggregation: { + columns: {}, + dimensions: { + date: 'date' + }, + placement: 'centroid', + resolution: 1, + threshold: 1 + }, + dates_as_numbers: opts.dates_as_numbers, + metadata: { + geometryType: true, + columnStats: { + topCategories: 32768, + includeNulls: true + }, + sample: { + num_rows: 1000, + include_columns: [ + 'date' + ] } } - ] + } }; }