Add tests

This commit is contained in:
Ubuntu 2018-06-01 10:08:34 +00:00
parent 79962a7566
commit 6872d57581
2 changed files with 125 additions and 0 deletions

View File

@ -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();
});
});
});
});

51
test/fixtures/test_mapconfigFactory.js vendored Normal file
View File

@ -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 };