From a5f985257c8a42f8d96dcf30fe99629d591aff1d Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 18 Jun 2018 13:14:17 +0200 Subject: [PATCH] Tests for dates_as_numbers with tokens --- test/acceptance/date-wrapping.spec.js | 53 +++++++++++++++++++++++++- test/fixtures/test_mapconfigFactory.js | 4 +- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/test/acceptance/date-wrapping.spec.js b/test/acceptance/date-wrapping.spec.js index 9bb8098f..4ba5bbf5 100644 --- a/test/acceptance/date-wrapping.spec.js +++ b/test/acceptance/date-wrapping.spec.js @@ -262,4 +262,55 @@ describe('date-wrapping', () => { }); }); }); -}); \ No newline at end of file + + describe('when sql queries use mapnik tokens', () => { + beforeEach(() => { + const mapConfig = mapConfigFactory.getVectorMapConfig({ + layerOptions: [{ + dates_as_numbers: true, + additionalColumns: [ + '!scale_denominator! AS sc' + ] + }] + }); + testClient = new TestClient(mapConfig); + }); + + afterEach(done => testClient.drain(done)); + + it.only('should work', done => { + testClient.getLayergroup(function(err, layergroup) { + assert.ifError(err); + assert.deepEqual(layergroup.metadata.layers[0].meta.dates_as_numbers, ['date']); + done(); + }); + + }); + + it.only('should return correct tiles', done => { + testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => { + const expected = [ + { + type: 'Feature', + id: 1, + geometry: { type: 'Point', coordinates: [0, 0] }, + properties: { cartodb_id: 0, date: 1527810000, sc: 559082000 } + }, + { + type: 'Feature', + id: 2, + geometry: { type: 'Point', coordinates: [0, 0] }, + properties: { cartodb_id: 1, date: 1527900000, sc: 559082000 } + } + ]; + const actual = JSON.parse(mvt.toGeoJSONSync(0)).features; + + assert.deepEqual(actual, expected); + done(); + }); + }); + }); + +}); + + diff --git a/test/fixtures/test_mapconfigFactory.js b/test/fixtures/test_mapconfigFactory.js index ff554be5..f1af550c 100644 --- a/test/fixtures/test_mapconfigFactory.js +++ b/test/fixtures/test_mapconfigFactory.js @@ -18,16 +18,18 @@ function _generateLayers(opts) { } function _generateLayerConfig(opts) { + const additionalColumns = opts.additionalColumns ? opts.additionalColumns.join(',')+',' : ''; return { type: 'mapnik', options: { sql: ` SELECT + ${additionalColumns} (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 + FROM generate_series(0, 1) x`, aggregation: { columns: {},