Windshaft-cartodb/test/acceptance/overviews-metadata-test.js

307 lines
11 KiB
JavaScript
Raw Normal View History

'use strict';
2019-11-14 02:36:30 +08:00
var testHelper = require('../support/test-helper');
2016-01-22 00:36:25 +08:00
var assert = require('../support/assert');
2019-10-07 16:55:26 +08:00
var CartodbWindshaft = require('../../lib/server');
var serverOptions = require('../../lib/server-options');
2016-01-22 00:36:25 +08:00
2019-10-07 15:40:50 +08:00
var LayergroupToken = require('../../lib/models/layergroup-token');
2016-01-22 00:36:25 +08:00
var RedisPool = require('redis-mpool');
var step = require('step');
const MapStore = require('../support/map-store');
2016-01-22 00:36:25 +08:00
2019-10-22 01:07:24 +08:00
describe('overviews metadata', function () {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
2016-01-22 00:36:25 +08:00
// configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis);
2019-11-14 02:36:30 +08:00
var overviewsLayer = {
2016-01-22 00:36:25 +08:00
type: 'cartodb',
options: {
sql: 'SELECT * FROM test_table_overviews',
cartocss: '#layer { marker-fill: black; }',
cartocss_version: '2.3.0'
}
};
2019-11-14 02:36:30 +08:00
var nonOverviewsLayer = {
2016-01-22 00:36:25 +08:00
type: 'cartodb',
options: {
sql: 'SELECT * FROM test_table',
cartocss: '#layer { marker-fill: black; }',
cartocss_version: '2.3.0'
}
};
var keysToDelete;
2019-10-22 01:07:24 +08:00
beforeEach(function () {
2016-01-22 00:36:25 +08:00
keysToDelete = {};
});
2019-10-22 01:07:24 +08:00
afterEach(function (done) {
2019-11-14 02:36:30 +08:00
testHelper.deleteRedisKeys(keysToDelete, done);
2016-01-22 00:36:25 +08:00
});
2019-10-22 01:07:24 +08:00
it('layers with and without overviews', function (done) {
var layergroup = {
version: '1.0.0',
2019-11-14 02:36:30 +08:00
layers: [overviewsLayer, nonOverviewsLayer]
};
2019-11-14 02:36:30 +08:00
var layergroupUrl = '/api/v1/map';
2019-11-14 02:36:30 +08:00
var expectedToken;
step(
2019-11-14 02:36:30 +08:00
function doPost () {
2019-10-22 01:07:24 +08:00
var next = this;
assert.response(server, {
2019-11-14 02:36:30 +08:00
url: layergroupUrl,
2019-10-22 01:07:24 +08:00
method: 'POST',
headers: { host: 'localhost', 'Content-Type': 'application/json' },
data: JSON.stringify(layergroup)
}, {}, function (res) {
assert.strictEqual(res.statusCode, 200, res.body);
2019-10-22 01:07:24 +08:00
var parsedBody = JSON.parse(res.body);
assert.strictEqual(res.headers['x-layergroup-id'], parsedBody.layergroupid);
2019-11-14 02:36:30 +08:00
expectedToken = parsedBody.layergroupid;
2019-10-22 01:07:24 +08:00
next(null, res);
});
},
2019-11-14 02:36:30 +08:00
function doGetMapconfig (err) {
assert.ifError(err);
var next = this;
const mapStore = new MapStore(redisPool);
2019-11-14 02:36:30 +08:00
mapStore.load(LayergroupToken.parse(expectedToken).token, function (err, mapConfig) {
assert.ifError(err);
2019-11-14 02:36:30 +08:00
assert.deepStrictEqual(nonOverviewsLayer, mapConfig._cfg.layers[1]);
assert.strictEqual(mapConfig._cfg.layers[0].type, 'cartodb');
assert.ok(mapConfig._cfg.layers[0].options.query_rewrite_data);
2019-11-14 02:36:30 +08:00
var expectedData = {
overviews: {
test_table_overviews: {
schema: 'public',
1: { table: '_vovw_1_test_table_overviews' },
2: { table: '_vovw_2_test_table_overviews' }
}
}
2019-10-22 01:07:24 +08:00
};
2019-11-14 02:36:30 +08:00
assert.deepStrictEqual(mapConfig._cfg.layers[0].options.query_rewrite_data, expectedData);
2019-10-22 01:07:24 +08:00
});
2019-10-22 01:07:24 +08:00
next(err);
},
2019-10-22 01:07:24 +08:00
function finish (err) {
2019-11-14 02:36:30 +08:00
keysToDelete['map_cfg|' + LayergroupToken.parse(expectedToken).token] = 0;
keysToDelete['user:localhost:mapviews:global'] = 5;
done(err);
}
);
2016-01-22 00:36:25 +08:00
});
describe('Overviews Flags', function () {
2019-10-22 01:07:24 +08:00
it('Overviews used', function (done) {
var layergroup = {
version: '1.0.0',
2019-11-14 02:36:30 +08:00
layers: [overviewsLayer, nonOverviewsLayer]
};
2019-11-14 02:36:30 +08:00
var layergroupUrl = '/api/v1/map';
2019-11-14 02:36:30 +08:00
var expectedToken;
step(
2019-11-14 02:36:30 +08:00
function doPost () {
var next = this;
assert.response(server, {
2019-11-14 02:36:30 +08:00
url: layergroupUrl,
method: 'POST',
headers: { host: 'localhost', 'Content-Type': 'application/json' },
data: JSON.stringify(layergroup)
}, {}, function (res) {
assert.strictEqual(res.statusCode, 200, res.body);
const headers = JSON.parse(res.headers['x-tiler-profiler']);
assert.ok(headers.overviewsAddedToMapconfig);
assert.strictEqual(headers.mapType, 'anonymous');
const parsedBody = JSON.parse(res.body);
2019-11-14 02:36:30 +08:00
expectedToken = parsedBody.layergroupid;
next();
});
},
2019-10-22 01:07:24 +08:00
function finish (err) {
2019-11-14 02:36:30 +08:00
keysToDelete['map_cfg|' + LayergroupToken.parse(expectedToken).token] = 0;
keysToDelete['user:localhost:mapviews:global'] = 5;
done(err);
}
);
});
2019-10-22 01:07:24 +08:00
it('Overviews NOT used', function (done) {
var layergroup = {
version: '1.0.0',
2019-11-14 02:36:30 +08:00
layers: [nonOverviewsLayer]
};
2019-11-14 02:36:30 +08:00
var layergroupUrl = '/api/v1/map';
2019-11-14 02:36:30 +08:00
var expectedToken;
step(
2019-11-14 02:36:30 +08:00
function doPost () {
var next = this;
assert.response(server, {
2019-11-14 02:36:30 +08:00
url: layergroupUrl,
method: 'POST',
headers: { host: 'localhost', 'Content-Type': 'application/json' },
data: JSON.stringify(layergroup)
}, {}, function (res) {
assert.strictEqual(res.statusCode, 200, res.body);
const headers = JSON.parse(res.headers['x-tiler-profiler']);
assert.strictEqual(headers.overviewsAddedToMapconfig, false);
assert.strictEqual(headers.mapType, 'anonymous');
const parsedBody = JSON.parse(res.body);
2019-11-14 02:36:30 +08:00
expectedToken = parsedBody.layergroupid;
next();
});
},
2019-10-22 01:07:24 +08:00
function finish (err) {
2019-11-14 02:36:30 +08:00
keysToDelete['map_cfg|' + LayergroupToken.parse(expectedToken).token] = 0;
keysToDelete['user:localhost:mapviews:global'] = 5;
done(err);
}
);
});
});
2016-01-22 00:36:25 +08:00
});
2016-05-18 17:45:14 +08:00
2019-10-22 01:07:24 +08:00
describe('overviews metadata with filters', function () {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
2016-05-18 17:45:14 +08:00
// configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis);
var keysToDelete;
2019-10-22 01:07:24 +08:00
beforeEach(function () {
2016-05-18 17:45:14 +08:00
keysToDelete = {};
});
2019-10-22 01:07:24 +08:00
afterEach(function (done) {
2019-11-14 02:36:30 +08:00
testHelper.deleteRedisKeys(keysToDelete, done);
2016-05-18 17:45:14 +08:00
});
2019-10-22 01:07:24 +08:00
it('layers with overviews', function (done) {
var layergroup = {
2016-05-18 17:45:14 +08:00
version: '1.5.0',
layers: [
2019-10-22 01:07:24 +08:00
{
type: 'cartodb',
options: {
sql: 'SELECT * FROM test_table_overviews',
source: { id: 'with_overviews' },
cartocss: '#layer { marker-fill: black; }',
cartocss_version: '2.3.0'
}
}
2016-05-18 17:45:14 +08:00
],
2019-10-22 01:07:24 +08:00
dataviews: {
2016-05-18 17:45:14 +08:00
test_names: {
type: 'aggregation',
2019-10-22 01:07:24 +08:00
source: { id: 'with_overviews' },
2016-05-18 17:45:14 +08:00
options: {
column: 'name',
aggregation: 'count'
}
}
},
analyses: [
2019-10-22 01:07:24 +08:00
{
id: 'with_overviews',
2016-05-18 17:45:14 +08:00
type: 'source',
params: {
2019-10-22 01:07:24 +08:00
query: 'select * from test_table_overviews'
2016-05-18 17:45:14 +08:00
}
}
]
};
var filters = {
dataviews: {
test_names: { accept: ['Hawai'] }
}
};
2019-11-14 02:36:30 +08:00
var layergroupUrl = '/api/v1/map';
2016-05-18 17:45:14 +08:00
2019-11-14 02:36:30 +08:00
var expectedToken;
2016-05-18 17:45:14 +08:00
step(
2019-11-14 02:36:30 +08:00
function doPost () {
2019-10-22 01:07:24 +08:00
var next = this;
assert.response(server, {
2019-11-14 02:36:30 +08:00
url: layergroupUrl + '?filters=' + JSON.stringify(filters),
2019-10-22 01:07:24 +08:00
method: 'POST',
headers: { host: 'localhost', 'Content-Type': 'application/json' },
data: JSON.stringify(layergroup)
}, {}, function (res) {
assert.strictEqual(res.statusCode, 200, res.body);
2019-10-22 01:07:24 +08:00
var parsedBody = JSON.parse(res.body);
assert.strictEqual(res.headers['x-layergroup-id'], parsedBody.layergroupid);
2019-11-14 02:36:30 +08:00
expectedToken = parsedBody.layergroupid;
2019-10-22 01:07:24 +08:00
next(null, res);
});
2016-05-18 17:45:14 +08:00
},
2019-11-14 02:36:30 +08:00
function doGetMapconfig (err) {
2016-05-18 17:45:14 +08:00
assert.ifError(err);
var next = this;
const mapStore = new MapStore(redisPool);
2019-11-14 02:36:30 +08:00
mapStore.load(LayergroupToken.parse(expectedToken).token, function (err, mapConfig) {
2016-05-18 17:45:14 +08:00
assert.ifError(err);
assert.strictEqual(mapConfig._cfg.layers[0].type, 'cartodb');
2016-05-18 17:45:14 +08:00
assert.ok(mapConfig._cfg.layers[0].options.query_rewrite_data);
2019-11-14 02:36:30 +08:00
var expectedData = {
2016-05-18 17:45:14 +08:00
overviews: {
test_table_overviews: {
schema: 'public',
1: { table: '_vovw_1_test_table_overviews' },
2: { table: '_vovw_2_test_table_overviews' }
}
},
2019-10-22 01:07:24 +08:00
filters: { test_names: { type: 'category', column: 'name', params: { accept: ['Hawai'] } } },
2016-05-18 17:45:14 +08:00
unfiltered_query: 'select * from test_table_overviews',
filter_stats: { unfiltered_rows: 5, filtered_rows: 1 }
2019-10-22 01:07:24 +08:00
};
2019-11-14 02:36:30 +08:00
assert.deepStrictEqual(mapConfig._cfg.layers[0].options.query_rewrite_data, expectedData);
2019-10-22 01:07:24 +08:00
});
2016-05-18 17:45:14 +08:00
2019-10-22 01:07:24 +08:00
next(err);
2016-05-18 17:45:14 +08:00
},
2019-10-22 01:07:24 +08:00
function finish (err) {
2019-11-14 02:36:30 +08:00
keysToDelete['map_cfg|' + LayergroupToken.parse(expectedToken).token] = 0;
2016-05-18 17:45:14 +08:00
keysToDelete['user:localhost:mapviews:global'] = 5;
done(err);
}
);
});
});