2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-06-01 18:08:34 +08:00
|
|
|
const assert = require('assert');
|
|
|
|
const TestClient = require('../support/test-client');
|
|
|
|
const mapConfigFactory = require('../fixtures/test_mapconfigFactory');
|
2019-10-07 16:10:51 +08:00
|
|
|
const serverOptions = require('../../lib/server-options');
|
2018-06-01 18:08:34 +08:00
|
|
|
|
2018-10-17 00:27:27 +08:00
|
|
|
const usePgMvtRenderer = serverOptions.renderer.mvt.usePostGIS;
|
2019-11-14 03:08:04 +08:00
|
|
|
const describeMvt = !usePgMvtRenderer ? describe : describe.skip;
|
2018-10-17 00:27:27 +08:00
|
|
|
|
2019-11-14 03:08:04 +08:00
|
|
|
describeMvt('date-wrapping', () => {
|
2018-06-01 18:08:34 +08:00
|
|
|
let testClient;
|
|
|
|
|
2018-06-05 14:58:44 +08:00
|
|
|
describe('when a map instantiation has one single layer', () => {
|
|
|
|
describe('and the layer has the "dates_as_numbers" option enabled', () => {
|
|
|
|
beforeEach(() => {
|
2019-10-22 01:07:24 +08:00
|
|
|
const mapConfig = mapConfigFactory.getVectorMapConfig({ layerOptions: [{ dates_as_numbers: true }] });
|
2018-06-05 14:58:44 +08:00
|
|
|
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) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2018-06-05 14:58:44 +08:00
|
|
|
const expected = [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 0,
|
2018-06-05 14:58:44 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 0, date: 1527810000 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 1,
|
2018-06-05 14:58:44 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 1, date: 1527900000 }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const actual = JSON.parse(mvt.toGeoJSONSync(0)).features;
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(actual, expected);
|
2018-06-05 14:58:44 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-06-05 17:25:00 +08:00
|
|
|
|
|
|
|
it('should return metadata with casted columns', done => {
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroup) {
|
2018-06-05 17:25:00 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(layergroup.metadata.layers[0].meta.dates_as_numbers, ['date']);
|
2018-06-05 17:44:30 +08:00
|
|
|
done();
|
2018-06-05 17:25:00 +08:00
|
|
|
});
|
|
|
|
});
|
2018-06-01 18:08:34 +08:00
|
|
|
});
|
|
|
|
|
2018-06-05 14:58:44 +08:00
|
|
|
describe('and the layer has the "dates_as_numbers" option disabled', () => {
|
|
|
|
beforeEach(() => {
|
2019-10-22 01:07:24 +08:00
|
|
|
const mapConfig = mapConfigFactory.getVectorMapConfig({ layerOptions: [{ dates_as_numbers: false }] });
|
2018-06-05 14:58:44 +08:00
|
|
|
testClient = new TestClient(mapConfig);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(done => testClient.drain(done));
|
2018-06-01 18:08:34 +08:00
|
|
|
|
2018-06-05 14:58:44 +08:00
|
|
|
it('should return date columns as dates', done => {
|
|
|
|
testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2018-06-05 14:58:44 +08:00
|
|
|
const expected = [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 0,
|
2018-06-05 14:58:44 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 0 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 1,
|
2018-06-05 14:58:44 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 1 }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const actual = JSON.parse(mvt.toGeoJSONSync(0)).features;
|
2018-06-01 18:08:34 +08:00
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(actual, expected);
|
2018-06-05 14:58:44 +08:00
|
|
|
done();
|
|
|
|
});
|
2018-06-01 18:08:34 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-05 14:58:44 +08:00
|
|
|
describe('when a map instantiation has multiple layers', () => {
|
2018-06-12 01:31:15 +08:00
|
|
|
afterEach(done => testClient.drain(done));
|
|
|
|
|
2018-06-05 14:58:44 +08:00
|
|
|
describe('and both layers have the "dates_as_numbers" option enabled', () => {
|
2018-06-12 01:31:15 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
const mapConfig = mapConfigFactory.getVectorMapConfig({
|
|
|
|
numberOfLayers: 2,
|
|
|
|
layerOptions: [
|
|
|
|
{ dates_as_numbers: true },
|
|
|
|
{ dates_as_numbers: true }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
testClient = new TestClient(mapConfig);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return dates as numbers for every layer', done => {
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroup) {
|
2018-06-12 01:31:15 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(layergroup.metadata.layers[0].meta.dates_as_numbers, ['date']);
|
|
|
|
assert.deepStrictEqual(layergroup.metadata.layers[1].meta.dates_as_numbers, ['date']);
|
2018-06-12 01:31:15 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2018-06-12 01:31:15 +08:00
|
|
|
const expected0 = [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 0,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 0, date: 1527810000 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 1,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 1, date: 1527900000 }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const expected1 = [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 0,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 0, date: 1527810000 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 1,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 1, date: 1527900000 }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const actual0 = JSON.parse(mvt.toGeoJSONSync(0)).features;
|
|
|
|
const actual1 = JSON.parse(mvt.toGeoJSONSync(1)).features;
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(actual0, expected0);
|
|
|
|
assert.deepStrictEqual(actual1, expected1);
|
2018-06-12 01:31:15 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-06-05 14:58:44 +08:00
|
|
|
});
|
2018-06-01 18:08:34 +08:00
|
|
|
|
2018-06-05 14:58:44 +08:00
|
|
|
describe('and only one layers has the "dates_as_numbers" option enabled', () => {
|
2018-06-12 01:31:15 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
const mapConfig = mapConfigFactory.getVectorMapConfig({
|
|
|
|
numberOfLayers: 2,
|
|
|
|
layerOptions: [
|
|
|
|
{ dates_as_numbers: false },
|
|
|
|
{ dates_as_numbers: true }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
testClient = new TestClient(mapConfig);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return dates as numbers only for the layer with the "dates_as_numbers" flag enabled', done => {
|
|
|
|
testClient.getLayergroup(function (err, layergroup) {
|
2018-06-12 01:31:15 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(layergroup.metadata.layers[0].meta.dates_as_numbers || [], []);
|
|
|
|
assert.deepStrictEqual(layergroup.metadata.layers[1].meta.dates_as_numbers, ['date']);
|
2018-06-12 01:31:15 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2018-06-12 01:31:15 +08:00
|
|
|
const expected0 = [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 0,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 0 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 1,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 1 }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const expected1 = [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 0,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 0, date: 1527810000 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 1,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 1, date: 1527900000 }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const actual0 = JSON.parse(mvt.toGeoJSONSync(0)).features;
|
|
|
|
const actual1 = JSON.parse(mvt.toGeoJSONSync(1)).features;
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(actual0, expected0);
|
|
|
|
assert.deepStrictEqual(actual1, expected1);
|
2018-06-12 01:31:15 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-06-05 14:58:44 +08:00
|
|
|
});
|
2018-06-01 18:08:34 +08:00
|
|
|
|
2018-06-05 14:58:44 +08:00
|
|
|
describe('and none of the layers has the "dates_as_numbers" option enabled', () => {
|
2018-06-12 01:31:15 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
const mapConfig = mapConfigFactory.getVectorMapConfig({
|
|
|
|
numberOfLayers: 2,
|
|
|
|
layerOptions: [
|
|
|
|
{ dates_as_numbers: false },
|
|
|
|
{ dates_as_numbers: false }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
testClient = new TestClient(mapConfig);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return dates as dates for both layers', done => {
|
|
|
|
testClient.getLayergroup(function (err, layergroup) {
|
2018-06-12 01:31:15 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(layergroup.metadata.layers[0].meta.dates_as_numbers || [], []);
|
|
|
|
assert.deepStrictEqual(layergroup.metadata.layers[1].meta.dates_as_numbers || [], []);
|
2018-06-12 01:31:15 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2018-06-12 01:31:15 +08:00
|
|
|
const expected0 = [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 0,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 0 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 1,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 1 }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const expected1 = [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 0,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 0 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 1,
|
2018-06-12 01:31:15 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
|
|
|
properties: { _cdb_feature_count: 1, cartodb_id: 1 }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const actual0 = JSON.parse(mvt.toGeoJSONSync(0)).features;
|
|
|
|
const actual1 = JSON.parse(mvt.toGeoJSONSync(1)).features;
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(actual0, expected0);
|
|
|
|
assert.deepStrictEqual(actual1, expected1);
|
2018-06-12 01:31:15 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-06-01 18:08:34 +08:00
|
|
|
});
|
|
|
|
});
|
2018-06-18 19:14:17 +08:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2018-06-18 19:33:08 +08:00
|
|
|
it('should work', done => {
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroup) {
|
2018-06-18 19:14:17 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(layergroup.metadata.layers[0].meta.dates_as_numbers, ['date']);
|
2018-06-18 19:14:17 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-18 19:33:08 +08:00
|
|
|
it('should return correct tiles', done => {
|
2018-06-18 19:14:17 +08:00
|
|
|
testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, mvt) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2018-06-18 19:14:17 +08:00
|
|
|
const expected = [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 0,
|
2018-06-18 19:14:17 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
2018-10-16 21:55:59 +08:00
|
|
|
properties: { cartodb_id: 0, date: 1527810000, sc: 559082264.0287178839788058162356 }
|
2018-06-18 19:14:17 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
2018-10-16 21:41:34 +08:00
|
|
|
id: 1,
|
2018-06-18 19:14:17 +08:00
|
|
|
geometry: { type: 'Point', coordinates: [0, 0] },
|
2018-10-16 21:55:59 +08:00
|
|
|
properties: { cartodb_id: 1, date: 1527900000, sc: 559082264.0287178839788058162356 }
|
2018-06-18 19:14:17 +08:00
|
|
|
}
|
|
|
|
];
|
|
|
|
const actual = JSON.parse(mvt.toGeoJSONSync(0)).features;
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(actual, expected);
|
2018-06-18 19:14:17 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|