2019-07-04 21:34:37 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('../../support/test_helper');
|
|
|
|
|
|
|
|
const assert = require('../../support/assert');
|
|
|
|
const TestClient = require('../../support/test-client');
|
|
|
|
|
|
|
|
const ONE_YEAR_IN_SECONDS = 60 * 60 * 24 * 365;
|
|
|
|
const FIVE_MINUTES_IN_SECONDS = 60 * 5;
|
|
|
|
|
|
|
|
const defaultLayers = [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: TestClient.SQL.ONE_POINT,
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}];
|
2019-07-08 23:55:04 +08:00
|
|
|
const defaultDatavies = {};
|
|
|
|
const defaultAnalyses = [];
|
|
|
|
|
|
|
|
function createMapConfig ({
|
|
|
|
layers = defaultLayers,
|
|
|
|
dataviews = defaultDatavies,
|
|
|
|
analyses = defaultAnalyses
|
|
|
|
} = {}) {
|
2019-07-04 21:34:37 +08:00
|
|
|
return {
|
|
|
|
version: '1.8.0',
|
2019-07-08 23:55:04 +08:00
|
|
|
layers: layers,
|
|
|
|
dataviews: dataviews || {},
|
|
|
|
analyses: analyses || []
|
2019-07-04 21:34:37 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-07-09 00:08:08 +08:00
|
|
|
describe('cache-control header', function () {
|
2019-07-04 21:34:37 +08:00
|
|
|
describe('max-age directive', function () {
|
2019-07-04 22:18:43 +08:00
|
|
|
it('tile from a table which is included in cdb_tablemetada', function (done) {
|
2019-07-04 21:34:37 +08:00
|
|
|
const ttl = ONE_YEAR_IN_SECONDS;
|
2019-07-09 20:47:40 +08:00
|
|
|
const mapConfig = createMapConfig({
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
2019-07-04 21:34:37 +08:00
|
|
|
|
|
|
|
const testClient = new TestClient(mapConfig);
|
|
|
|
|
|
|
|
testClient.getTile(0, 0, 0, {}, function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(res.headers['cache-control'], `public,max-age=${ttl}`);
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-04 22:18:43 +08:00
|
|
|
it('tile from a table which is NOT included in cdb_tablemetada', function (done) {
|
2019-07-04 21:34:37 +08:00
|
|
|
const ttl = global.environment.varnish.fallbackTtl || FIVE_MINUTES_IN_SECONDS;
|
2019-07-09 20:47:40 +08:00
|
|
|
const mapConfig = createMapConfig({
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_2',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
2019-07-04 21:34:37 +08:00
|
|
|
|
|
|
|
const testClient = new TestClient(mapConfig);
|
|
|
|
|
|
|
|
testClient.getTile(0, 0, 0, {}, function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(res.headers['cache-control'], `public,max-age=${ttl}`);
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-04 21:58:39 +08:00
|
|
|
it('tile from joined tables which one of them is NOT included in cdb_tablemetada', function (done) {
|
2019-07-04 21:34:37 +08:00
|
|
|
const ttl = global.environment.varnish.fallbackTtl || FIVE_MINUTES_IN_SECONDS;
|
2019-07-09 20:47:40 +08:00
|
|
|
const mapConfig = createMapConfig({
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: `
|
|
|
|
select
|
|
|
|
t.cartodb_id,
|
|
|
|
t.the_geom,
|
|
|
|
t.the_geom_webmercator
|
|
|
|
from
|
|
|
|
test_table t,
|
|
|
|
test_table_2 t2
|
|
|
|
where
|
|
|
|
t.cartodb_id = t2.cartodb_id
|
|
|
|
`,
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
2019-07-04 21:58:39 +08:00
|
|
|
|
|
|
|
const testClient = new TestClient(mapConfig);
|
|
|
|
|
|
|
|
testClient.getTile(0, 0, 0, {}, function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(res.headers['cache-control'], `public,max-age=${ttl}`);
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('tile from a dynamic query which doesn\'t use a table' , function (done) {
|
|
|
|
const ttl = ONE_YEAR_IN_SECONDS;
|
2019-07-04 21:34:37 +08:00
|
|
|
const mapConfig = createMapConfig();
|
|
|
|
|
|
|
|
const testClient = new TestClient(mapConfig);
|
|
|
|
|
|
|
|
testClient.getTile(0, 0, 0, {}, function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(res.headers['cache-control'], `public,max-age=${ttl}`);
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2019-07-08 23:55:04 +08:00
|
|
|
|
|
|
|
it('tile from a cached analysis table which is not included in cdb_tablemetada', function (done) {
|
|
|
|
const ttl = ONE_YEAR_IN_SECONDS;
|
|
|
|
const mapConfig = createMapConfig({
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD'
|
|
|
|
},
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
analyses: [{
|
|
|
|
id: 'HEAD',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'source_1',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
2019-07-09 00:05:30 +08:00
|
|
|
query: 'select * from test_table'
|
2019-07-08 23:55:04 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
radius: 60000
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
const testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
2019-07-09 20:59:16 +08:00
|
|
|
testClient.getTile(0, 0, 0, {}, function (err, res) {
|
2019-07-08 23:55:04 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(res.headers['cache-control'], `public,max-age=${ttl}`);
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2019-07-04 21:34:37 +08:00
|
|
|
});
|
|
|
|
});
|