From 6872d575813c3c1eee9635a5079d7f609d4243dc Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 1 Jun 2018 10:08:34 +0000 Subject: [PATCH] Add tests --- test/acceptance/date-wrapping.spec.js | 74 ++++++++++++++++++++++++++ test/fixtures/test_mapconfigFactory.js | 51 ++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 test/acceptance/date-wrapping.spec.js create mode 100644 test/fixtures/test_mapconfigFactory.js diff --git a/test/acceptance/date-wrapping.spec.js b/test/acceptance/date-wrapping.spec.js new file mode 100644 index 00000000..5b8953a0 --- /dev/null +++ b/test/acceptance/date-wrapping.spec.js @@ -0,0 +1,74 @@ +/* eslint-env mocha */ +const assert = require('assert'); +const TestClient = require('../support/test-client'); +const mapConfigFactory = require('../fixtures/test_mapconfigFactory'); + +describe.only('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); + }); + + 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(); + }); + }); + }); + + describe('when a map instantiation has the "dates_as_numbers" option disabled', () => { + beforeEach(() => { + const mapConfig = mapConfigFactory.getVectorMapConfig({ dates_as_numbers: false }); + testClient = new TestClient(mapConfig); + }); + + afterEach(done => testClient.drain(done)); + + 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(); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/fixtures/test_mapconfigFactory.js b/test/fixtures/test_mapconfigFactory.js new file mode 100644 index 00000000..54643475 --- /dev/null +++ b/test/fixtures/test_mapconfigFactory.js @@ -0,0 +1,51 @@ + +function getVectorMapConfig(opts) { + return { + 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' + ] + } + } + } + } + ] + }; +} + + + + +module.exports = { getVectorMapConfig }; \ No newline at end of file