Windshaft-cartodb/test/acceptance/date-wrapping.spec.js

98 lines
3.9 KiB
JavaScript
Raw Normal View History

2018-06-01 18:08:34 +08:00
/* eslint-env mocha */
const assert = require('assert');
const TestClient = require('../support/test-client');
const mapConfigFactory = require('../fixtures/test_mapconfigFactory');
2018-06-01 18:18:07 +08:00
describe('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(() => {
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();
});
});
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(() => {
const mapConfig = mapConfigFactory.getVectorMapConfig({ dates_as_numbers: false });
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 => {
2018-06-01 18:08:34 +08:00
2018-06-05 14:58:44 +08:00
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;
2018-06-01 18:08:34 +08:00
2018-06-05 14:58:44 +08:00
assert.deepEqual(actual, expected);
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-01 18:08:34 +08:00
beforeEach(() => {
2018-06-05 14:58:44 +08:00
const mapConfig = mapConfigFactory.getVectorMapConfig({ numberOfLayers: 2 });
2018-06-01 18:08:34 +08:00
testClient = new TestClient(mapConfig);
});
2018-06-05 14:58:44 +08:00
describe('and both layers have the "dates_as_numbers" option enabled', () => {
// TODO: Pending test
it('should return dates as numbers for every layer');
});
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', () => {
// TODO: Pending test
it('should return dates as numbers only for the layer with the "dates_as_numbers" flag enabled');
});
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', () => {
// TODO: Pending test
it('should return dates as dates for both layers');
2018-06-01 18:08:34 +08:00
});
});
});