Windshaft-cartodb/test/acceptance/mvt-regressions.js

182 lines
5.8 KiB
JavaScript
Raw Normal View History

'use strict';
require('../support/test_helper');
const assert = require('../support/assert');
const TestClient = require('../support/test-client');
const serverOptions = require('../../lib/cartodb/server_options');
const suites = [{
2018-04-11 22:08:18 +08:00
desc: 'mapnik',
usePostGIS: false
}];
if (process.env.POSTGIS_VERSION >= '20400') {
suites.push({
2018-04-11 22:08:18 +08:00
desc: 'postgis',
usePostGIS: true
});
}
2018-04-11 22:08:18 +08:00
describe('mvt regressions', function () {
suites.forEach((suite) => {
const { desc, usePostGIS } = suite;
describe(desc, function () {
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
before(function () {
serverOptions.renderer.mvt.usePostGIS = usePostGIS;
});
after(function (){
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
});
afterEach(function (done) {
this.testClient.drain(done);
});
2018-04-11 22:08:18 +08:00
it('should not error on missing column from aggregation', function (done) {
const mapConfig = {
version: '1.7.0',
layers: [
{
type: 'cartodb',
options: {
sql: 'select * from populated_places_simple_reduced',
aggregation: {
placement: 'point-sample',
columns: {
pop_max_avg: {
aggregate_function: 'avg',
aggregated_column: 'pop_max'
}
},
threshold: 1
}
}
}
]
};
this.testClient = new TestClient(mapConfig);
this.testClient.getLayergroup((err, body) => {
if (err) {
return done(err);
}
assert.equal(typeof body.metadata, 'object');
assert.ok(Array.isArray(body.metadata.layers));
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
done();
});
});
});
});
});
2018-04-11 18:13:24 +08:00
describe('MVT Mapnik', function () {
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
before(function () {
serverOptions.renderer.mvt.usePostGIS = false;
});
after(function (){
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
});
afterEach(function (done) {
this.testClient.drain(done);
});
it('invalid properties', function (done) {
2018-04-17 17:05:37 +08:00
const query = `
select ldc, cartodb_id, _2016_6_partcntry, the_geom_webmercator, country
from countries_null_values
2018-04-17 17:05:37 +08:00
where country = 'Kenya' OR country = 'Sudan' LIMIT 3
`;
const mapConfig = {
version: '1.7.0',
layers: [
{
type: 'cartodb',
options: {
2018-04-17 17:05:37 +08:00
sql: query
}
}
]
};
const handler = (resolve, reject) => {
return (err, res, MVT) => {
if (err) {
return reject(err);
}
try {
const geojsonTile = JSON.parse(MVT.toGeoJSONSync(0));
const sudanFeature = geojsonTile.features.filter(_ => {
return _.properties.country === 'Sudan';
})[0];
if (!sudanFeature) {
return reject(new Error(`Missing country='Sudan'`));
}
resolve(sudanFeature);
} catch (err) {
resolve(err);
}
};
};
this.testClient = new TestClient(mapConfig);
const tile487 = new Promise((resolve, reject) => {
this.testClient.getTile(4, 8, 7, { format: 'mvt', layer: 0 }, handler(resolve, reject));
});
const tile497 = new Promise((resolve, reject) => {
this.testClient.getTile(4, 9, 7, { format: 'mvt', layer: 0 }, handler(resolve, reject));
});
Promise.all([tile487, tile497])
.then(features => {
const [tile487SudanFeature, tile497SudanFeature] = features;
assert.strictEqual(tile487SudanFeature.properties._2016_6_partcntry, 0);
assert.strictEqual(tile497SudanFeature.properties._2016_6_partcntry, 0);
return done();
})
.catch(err => done(err));
});
it('should not convert boolean to numeric', function (done) {
const geomWebmercator = 'st_transform(st_setsrid(st_makepoint(10, 10), 4326), 3857) as the_geom_webmercator';
const sql = `SELECT ${geomWebmercator}, FALSE as status, 0 as data`;
const mapConfig = {
version: '1.7.0',
layers: [
{
type: 'cartodb',
options: { sql }
}
]
};
this.testClient = new TestClient(mapConfig);
this.testClient.getTile(0, 0, 0, { format: 'mvt', layer: 0 }, (err, res, MVT) => {
if (err) {
return done(err);
}
const geojsonTile = JSON.parse(MVT.toGeoJSONSync(0));
assert.strictEqual(geojsonTile.features[0].properties.status, false);
2018-04-12 17:27:31 +08:00
assert.strictEqual(geojsonTile.features[0].properties.data, 0);
done();
});
});
2018-04-12 17:27:31 +08:00
});