2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2016-01-21 22:44:22 +08:00
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
var RedisPool = require('redis-mpool');
|
|
|
|
var cartodbRedis = require('cartodb-redis');
|
2019-10-07 15:43:40 +08:00
|
|
|
var PgConnection = require('../../lib/backends/pg-connection');
|
2019-10-07 15:45:46 +08:00
|
|
|
var PgQueryRunner = require('../../lib/backends/pg-query-runner');
|
2019-10-07 15:40:50 +08:00
|
|
|
var OverviewsMetadataBackend = require('../../lib/backends/overviews-metadata');
|
|
|
|
var FilterStatsBackend = require('../../lib/backends/filter-stats');
|
|
|
|
var MapConfigOverviewsAdapter = require('../../lib/models/mapconfig/adapter/mapconfig-overviews-adapter');
|
2016-01-21 22:44:22 +08:00
|
|
|
|
|
|
|
var redisPool = new RedisPool(global.environment.redis);
|
2019-10-22 01:07:24 +08:00
|
|
|
var metadataBackend = cartodbRedis({ pool: redisPool });
|
2016-01-21 22:44:22 +08:00
|
|
|
var pgConnection = new PgConnection(metadataBackend);
|
|
|
|
var pgQueryRunner = new PgQueryRunner(pgConnection);
|
2018-04-10 01:47:24 +08:00
|
|
|
var overviewsMetadataBackend = new OverviewsMetadataBackend(pgQueryRunner);
|
2018-04-10 00:56:01 +08:00
|
|
|
var filterStatsBackend = new FilterStatsBackend(pgQueryRunner);
|
2016-01-21 22:44:22 +08:00
|
|
|
|
2018-04-10 01:47:24 +08:00
|
|
|
var mapConfigOverviewsAdapter = new MapConfigOverviewsAdapter(overviewsMetadataBackend, filterStatsBackend);
|
2016-01-21 22:44:22 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('MapConfigOverviewsAdapter', function () {
|
|
|
|
it('should not modify layers for which no overviews are available', function (done) {
|
2016-01-21 22:44:22 +08:00
|
|
|
var sql = 'SELECT * FROM test_table';
|
|
|
|
var cartocss = '#layer { marker-fill: black; }';
|
2019-11-06 23:44:17 +08:00
|
|
|
var cartocssVersion = '2.3.0';
|
|
|
|
var layerWithoutOverviews = {
|
2016-01-21 22:44:22 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: sql,
|
|
|
|
cartocss: cartocss,
|
2019-11-06 23:44:17 +08:00
|
|
|
cartocss_version: cartocssVersion
|
2016-01-21 22:44:22 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-23 21:52:31 +08:00
|
|
|
var _mapConfig = {
|
2019-11-06 23:44:17 +08:00
|
|
|
layers: [layerWithoutOverviews]
|
2016-05-23 21:52:31 +08:00
|
|
|
};
|
|
|
|
|
2016-05-24 00:35:16 +08:00
|
|
|
var params = {};
|
|
|
|
var context = {};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
mapConfigOverviewsAdapter.getMapConfig('localhost', _mapConfig, params, context, function (err, mapConfig) {
|
2016-01-21 22:44:22 +08:00
|
|
|
assert.ok(!err);
|
2016-05-23 21:52:31 +08:00
|
|
|
var layers = mapConfig.layers;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layers.length, 1);
|
|
|
|
assert.strictEqual(layers[0].type, 'cartodb');
|
|
|
|
assert.strictEqual(layers[0].options.sql, sql);
|
|
|
|
assert.strictEqual(layers[0].options.cartocss, cartocss);
|
2019-11-06 23:44:17 +08:00
|
|
|
assert.strictEqual(layers[0].options.cartocss_version, cartocssVersion);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layers[0].options.overviews, undefined);
|
2016-01-21 22:44:22 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('MapConfigOverviewsAdapter', function () {
|
|
|
|
it('should add overviews metadata for layers using tables with overviews', function (done) {
|
2016-01-21 22:44:22 +08:00
|
|
|
var sql = 'SELECT * FROM test_table_overviews';
|
|
|
|
var cartocss = '#layer { marker-fill: black; }';
|
2019-11-06 23:44:17 +08:00
|
|
|
var cartocssVersion = '2.3.0';
|
|
|
|
var layerWithOverviews = {
|
2016-01-21 22:44:22 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: sql,
|
|
|
|
cartocss: cartocss,
|
2019-11-06 23:44:17 +08:00
|
|
|
cartocss_version: cartocssVersion
|
2016-01-21 22:44:22 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-23 21:52:31 +08:00
|
|
|
var _mapConfig = {
|
2019-11-06 23:44:17 +08:00
|
|
|
layers: [layerWithOverviews]
|
2016-05-23 21:52:31 +08:00
|
|
|
};
|
|
|
|
|
2016-05-24 00:35:16 +08:00
|
|
|
var params = {};
|
|
|
|
var context = {};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
mapConfigOverviewsAdapter.getMapConfig('localhost', _mapConfig, params, context, function (err, mapConfig) {
|
2016-01-21 22:44:22 +08:00
|
|
|
assert.ok(!err);
|
2016-05-23 21:52:31 +08:00
|
|
|
var layers = mapConfig.layers;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layers.length, 1);
|
|
|
|
assert.strictEqual(layers[0].type, 'cartodb');
|
|
|
|
assert.strictEqual(layers[0].options.sql, sql);
|
|
|
|
assert.strictEqual(layers[0].options.cartocss, cartocss);
|
2019-11-06 23:44:17 +08:00
|
|
|
assert.strictEqual(layers[0].options.cartocss_version, cartocssVersion);
|
2016-02-04 17:26:31 +08:00
|
|
|
assert.ok(layers[0].options.query_rewrite_data);
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedData = {
|
2016-04-20 23:47:43 +08:00
|
|
|
overviews: {
|
|
|
|
test_table_overviews: {
|
|
|
|
schema: 'public',
|
|
|
|
1: { table: '_vovw_1_test_table_overviews' },
|
|
|
|
2: { table: '_vovw_2_test_table_overviews' }
|
|
|
|
}
|
2016-02-04 17:26:31 +08:00
|
|
|
}
|
|
|
|
};
|
2019-11-06 23:44:17 +08:00
|
|
|
assert.deepStrictEqual(layers[0].options.query_rewrite_data, expectedData);
|
2016-01-21 22:44:22 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|