2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2016-05-12 00:24:47 +08:00
|
|
|
var assert = require('../support/assert');
|
2019-10-07 16:44:45 +08:00
|
|
|
const helper = require('../support/test-helper');
|
2016-05-12 00:24:47 +08:00
|
|
|
var TestClient = require('../support/test-client');
|
2019-10-07 15:40:50 +08:00
|
|
|
const LayergroupToken = require('../../lib/models/layergroup-token');
|
2020-06-02 17:57:11 +08:00
|
|
|
const createServer = require('../../lib/server');
|
2019-10-07 16:55:26 +08:00
|
|
|
const serverOptions = require('../../lib/server-options');
|
2016-05-12 00:24:47 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('regressions', function () {
|
2016-05-12 00:24:47 +08:00
|
|
|
var ERROR_RESPONSE = {
|
|
|
|
status: 400,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose a nice error when missing sql option', function (done) {
|
2016-05-12 00:24:47 +08:00
|
|
|
var mapConfig = {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
cartocss: '#polygons { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2016-05-12 00:24:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroupResult) {
|
2016-05-12 00:24:47 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroupResult.errors.length, 1);
|
|
|
|
assert.strictEqual(layergroupResult.errors[0], 'Missing sql for layer 0 options');
|
2016-05-12 00:24:47 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2018-04-13 01:58:33 +08:00
|
|
|
|
2018-05-14 18:28:57 +08:00
|
|
|
// See: https://github.com/CartoDB/Windshaft-cartodb/pull/956
|
|
|
|
it('"/user/localhost/api/v1/map" should create an anonymous map', function (done) {
|
2020-06-02 17:57:11 +08:00
|
|
|
const server = createServer(serverOptions);
|
2018-05-14 18:28:57 +08:00
|
|
|
const layergroup = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: TestClient.SQL.ONE_POINT,
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
const keysToDelete = {};
|
|
|
|
|
|
|
|
assert.response(server,
|
|
|
|
{
|
|
|
|
url: '/user/localhost/api/v1/map',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function (res, err) {
|
2018-05-14 18:28:57 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const body = JSON.parse(res.body);
|
|
|
|
assert.ok(body.layergroupid);
|
|
|
|
|
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(body.layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
helper.deleteRedisKeys(keysToDelete, done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-04-12 22:32:44 +08:00
|
|
|
describe('map instantiation', function () {
|
2018-04-13 00:24:00 +08:00
|
|
|
const apikeyToken = 'regular1';
|
2018-04-12 22:32:44 +08:00
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2018-04-13 00:24:00 +08:00
|
|
|
sql: 'select * from test_table_localhost_regular1',
|
2018-04-12 22:32:44 +08:00
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should have distint timestamps when the source was updated', function (done) {
|
2018-04-13 00:24:00 +08:00
|
|
|
const testClient = new TestClient(mapConfig, apikeyToken);
|
2018-04-12 22:32:44 +08:00
|
|
|
|
|
|
|
testClient.getLayergroup({}, (err, layergroup) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { cacheBuster: cacheBusterA } = LayergroupToken.parse(layergroup.layergroupid);
|
|
|
|
|
|
|
|
const conn = testClient.getDBConnection();
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
const sql = 'select CDB_TableMetadataTouch(\'test_table_localhost_regular1\'::regclass)';
|
2018-04-12 22:32:44 +08:00
|
|
|
|
|
|
|
conn.query(sql, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
testClient.getLayergroup({}, (err, layergroup) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { cacheBuster: cacheBusterB } = LayergroupToken.parse(layergroup.layergroupid);
|
|
|
|
|
|
|
|
const timestampA = parseInt(cacheBusterA, 10);
|
|
|
|
const timestampB = parseInt(cacheBusterB, 10);
|
|
|
|
|
2019-10-22 02:05:51 +08:00
|
|
|
assert.notStrictEqual(timestampA, timestampB);
|
2018-04-12 22:32:44 +08:00
|
|
|
assert.ok(timestampA < timestampB, `timestampA: ${timestampA} > timestampB:${timestampB}`);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-04-13 02:53:27 +08:00
|
|
|
|
2018-04-13 01:58:33 +08:00
|
|
|
it('should create and instantiate a named map with filters', function (done) {
|
|
|
|
const apikeyToken = '1234';
|
|
|
|
|
|
|
|
const template = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: 'regression-dataview-filter-template',
|
|
|
|
placeholders: {
|
|
|
|
buffersize: {
|
|
|
|
type: 'number',
|
|
|
|
default: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
version: '1.6.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'a1'
|
|
|
|
},
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
dataviews: {
|
|
|
|
country_places_count: {
|
|
|
|
source: {
|
|
|
|
id: 'a1'
|
|
|
|
},
|
|
|
|
type: 'aggregation',
|
|
|
|
options: {
|
|
|
|
column: 'adm0_a3',
|
|
|
|
aggregation: 'count'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
analyses: [
|
|
|
|
{
|
|
|
|
id: 'a1',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const testClient = new TestClient(template, apikeyToken);
|
2018-07-11 17:33:11 +08:00
|
|
|
testClient.keysToDelete['map_tpl|localhost'] = 0;
|
2018-04-13 01:58:33 +08:00
|
|
|
|
|
|
|
const params = {
|
|
|
|
own_filter: 1,
|
|
|
|
filters: {
|
|
|
|
dataviews: {
|
|
|
|
country_places_count: {
|
|
|
|
accept: ['CAN']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
testClient.getDataview('country_places_count', params, (err, dataview) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(dataview.type, 'aggregation');
|
|
|
|
assert.strictEqual(dataview.categories.length, 1);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(dataview.categories[0], { value: 256, category: 'CAN', agg: false });
|
2018-04-13 01:58:33 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2016-05-12 00:24:47 +08:00
|
|
|
});
|