2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-14 03:08:04 +08:00
|
|
|
var testHelper = require('../support/test-helper');
|
2016-04-01 00:36:50 +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-04-01 00:36:50 +08:00
|
|
|
|
2019-10-07 15:40:50 +08:00
|
|
|
var LayergroupToken = require('../../lib/models/layergroup-token');
|
2016-04-01 00:36:50 +08:00
|
|
|
|
|
|
|
var RedisPool = require('redis-mpool');
|
|
|
|
|
|
|
|
var step = require('step');
|
|
|
|
|
|
|
|
var windshaft = require('windshaft');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('overviews metadata for named maps', function () {
|
2018-04-16 22:16:23 +08:00
|
|
|
var server;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
server = new CartodbWindshaft(serverOptions);
|
|
|
|
});
|
2018-04-16 20:09:24 +08:00
|
|
|
|
2016-04-01 00:36:50 +08:00
|
|
|
// configure redis pool instance to use in tests
|
|
|
|
var redisPool = new RedisPool(global.environment.redis);
|
|
|
|
|
2019-11-14 03:08:04 +08:00
|
|
|
var overviewsLayer = {
|
2016-04-01 00:36:50 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'SELECT * FROM test_table_overviews',
|
|
|
|
cartocss: '#layer { marker-fill: black; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-14 03:08:04 +08:00
|
|
|
var nonOverviewsLayer = {
|
2016-04-01 00:36:50 +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-04-01 00:36:50 +08:00
|
|
|
keysToDelete = {};
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
afterEach(function (done) {
|
2019-11-14 03:08:04 +08:00
|
|
|
testHelper.deleteRedisKeys(keysToDelete, done);
|
2016-04-01 00:36:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
var templateId = 'overviews-template-1';
|
|
|
|
|
|
|
|
var template = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: templateId,
|
|
|
|
auth: { method: 'open' },
|
2019-10-22 01:07:24 +08:00
|
|
|
layergroup: {
|
2016-04-01 00:36:50 +08:00
|
|
|
version: '1.0.0',
|
2019-11-14 03:08:04 +08:00
|
|
|
layers: [overviewsLayer, nonOverviewsLayer]
|
2016-04-01 00:36:50 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should add overviews data to layers', function (done) {
|
2016-04-20 23:47:43 +08:00
|
|
|
step(
|
2019-10-22 01:07:24 +08:00
|
|
|
function postTemplate () {
|
|
|
|
var next = this;
|
|
|
|
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/map/named?api_key=1234',
|
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(template)
|
|
|
|
}, {}, function (res, err) {
|
|
|
|
next(err, res);
|
|
|
|
});
|
2016-04-20 23:47:43 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function checkTemplate (err, res) {
|
2016-04-20 23:47:43 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
var next = this;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(JSON.parse(res.body), {
|
2016-04-20 23:47:43 +08:00
|
|
|
template_id: templateId
|
|
|
|
});
|
|
|
|
next(null);
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function instantiateTemplate (err) {
|
2016-04-20 23:47:43 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/map/named/' + templateId,
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}, {},
|
2019-10-22 01:07:24 +08:00
|
|
|
function (res, err) {
|
2016-04-20 23:47:43 +08:00
|
|
|
return next(err, res);
|
|
|
|
});
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function checkInstanciation (err, res) {
|
2016-04-20 23:47:43 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
var next = this;
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200);
|
2016-04-20 23:47:43 +08:00
|
|
|
|
|
|
|
var parsedBody = JSON.parse(res.body);
|
|
|
|
|
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
|
|
|
|
assert.ok(parsedBody.layergroupid);
|
|
|
|
assert.ok(parsedBody.last_updated);
|
|
|
|
|
|
|
|
next(null, parsedBody.layergroupid);
|
|
|
|
},
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function checkMapconfig (err, layergroupId) {
|
2016-04-20 23:47:43 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
var next = this;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var mapStore = new windshaft.storage.MapStore({
|
2016-04-20 23:47:43 +08:00
|
|
|
pool: redisPool,
|
|
|
|
expire_time: 500000
|
|
|
|
});
|
2019-10-22 01:07:24 +08:00
|
|
|
mapStore.load(LayergroupToken.parse(layergroupId).token, function (err, mapConfig) {
|
2016-04-20 23:47:43 +08:00
|
|
|
assert.ifError(err);
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(nonOverviewsLayer, mapConfig._cfg.layers[1]);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(mapConfig._cfg.layers[0].type, 'cartodb');
|
2016-04-20 23:47:43 +08:00
|
|
|
assert.ok(mapConfig._cfg.layers[0].options.query_rewrite_data);
|
2019-11-14 03:08:04 +08:00
|
|
|
var expectedData = {
|
2016-04-20 23:47:43 +08:00
|
|
|
overviews: {
|
|
|
|
test_table_overviews: {
|
2019-10-22 01:07:24 +08:00
|
|
|
schema: 'public',
|
|
|
|
1: { table: '_vovw_1_test_table_overviews' },
|
|
|
|
2: { table: '_vovw_2_test_table_overviews' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-11-14 03:08:04 +08:00
|
|
|
assert.deepStrictEqual(mapConfig._cfg.layers[0].options.query_rewrite_data, expectedData);
|
2016-04-20 23:47:43 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
next(err);
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function deleteTemplate (err) {
|
2016-04-20 23:47:43 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
var next = this;
|
|
|
|
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/map/named/' + templateId + '?api_key=1234',
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: { host: 'localhost' }
|
|
|
|
}, {}, function (res, err) {
|
|
|
|
next(err, res);
|
|
|
|
});
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function checkDeleteTemplate (err, res) {
|
2016-04-20 23:47:43 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 204);
|
2016-04-20 23:47:43 +08:00
|
|
|
assert.ok(!res.body);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function finish (err) {
|
2016-04-20 23:47:43 +08:00
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
2016-04-01 00:36:50 +08:00
|
|
|
});
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('Overviews Flags', function () {
|
|
|
|
it('Overviews used', function (done) {
|
2018-09-05 18:39:51 +08:00
|
|
|
step(
|
2019-10-22 01:07:24 +08:00
|
|
|
function postTemplate () {
|
2018-09-05 18:39:51 +08:00
|
|
|
var next = this;
|
|
|
|
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/map/named?api_key=1234',
|
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(template)
|
|
|
|
}, {}, function (res, err) {
|
|
|
|
next(err, res);
|
|
|
|
});
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function instantiateTemplate (err) {
|
2018-09-05 18:39:51 +08:00
|
|
|
assert.ifError(err);
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2018-09-05 18:39:51 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/map/named/' + templateId,
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}, {},
|
2019-10-22 01:07:24 +08:00
|
|
|
function (res, err) {
|
|
|
|
return next(err, res);
|
|
|
|
});
|
2018-09-05 18:39:51 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function checkFlags (err, res) {
|
2018-09-05 18:39:51 +08:00
|
|
|
assert.ifError(err);
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2018-09-05 18:39:51 +08:00
|
|
|
var next = this;
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(res.body);
|
|
|
|
|
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
|
|
|
|
const headers = JSON.parse(res.headers['x-tiler-profiler']);
|
|
|
|
|
|
|
|
assert.ok(headers.overviewsAddedToMapconfig);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(headers.mapType, 'named');
|
2018-09-05 18:39:51 +08:00
|
|
|
|
|
|
|
next();
|
|
|
|
},
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function finish (err) {
|
2018-09-05 18:39:51 +08:00
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('Overviews NOT used', function (done) {
|
2018-09-05 18:39:51 +08:00
|
|
|
const nonOverviewsTemplateId = 'non-overviews-template';
|
|
|
|
|
|
|
|
var nonOverviewsTemplate = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: nonOverviewsTemplateId,
|
|
|
|
auth: { method: 'open' },
|
|
|
|
layergroup: {
|
|
|
|
version: '1.0.0',
|
2019-11-14 03:08:04 +08:00
|
|
|
layers: [nonOverviewsLayer]
|
2018-09-05 18:39:51 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
step(
|
2019-10-22 01:07:24 +08:00
|
|
|
function postTemplate () {
|
2018-09-05 18:39:51 +08:00
|
|
|
var next = this;
|
|
|
|
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/map/named?api_key=1234',
|
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(nonOverviewsTemplate)
|
|
|
|
}, {}, function (res, err) {
|
|
|
|
next(err, res);
|
2018-09-05 17:48:21 +08:00
|
|
|
});
|
2018-09-05 18:39:51 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function instantiateTemplate (err) {
|
2018-09-05 18:39:51 +08:00
|
|
|
assert.ifError(err);
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2018-09-05 18:39:51 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/map/named/' + nonOverviewsTemplateId,
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}, {},
|
2019-10-22 01:07:24 +08:00
|
|
|
function (res, err) {
|
|
|
|
return next(err, res);
|
|
|
|
});
|
2018-09-05 18:39:51 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function checkFlags (err, res) {
|
2018-09-05 18:39:51 +08:00
|
|
|
assert.ifError(err);
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2018-09-05 18:39:51 +08:00
|
|
|
var next = this;
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2018-09-05 18:39:51 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2018-09-05 18:39:51 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2018-09-05 18:39:51 +08:00
|
|
|
const headers = JSON.parse(res.headers['x-tiler-profiler']);
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(headers.overviewsAddedToMapconfig, false);
|
|
|
|
assert.strictEqual(headers.mapType, 'named');
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2018-09-05 18:39:51 +08:00
|
|
|
next();
|
|
|
|
},
|
2018-09-05 17:48:21 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function finish (err) {
|
2018-09-05 18:39:51 +08:00
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-09-05 17:48:21 +08:00
|
|
|
});
|
2016-04-01 00:36:50 +08:00
|
|
|
});
|