Windshaft-cartodb/test/acceptance/cache/cache-control-header.js

174 lines
5.6 KiB
JavaScript
Raw Normal View History

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'
}
}];
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',
layers: layers,
dataviews: dataviews || {},
analyses: analyses || []
2019-07-04 21:34:37 +08:00
};
}
describe.only('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;
const mapConfig = createMapConfig([{
type: 'cartodb',
options: {
sql: 'select * from test_table',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0'
}
}]);
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;
const mapConfig = createMapConfig([{
type: 'cartodb',
options: {
sql: 'select * from test_table_2',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0'
}
}]);
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-04 21:58:39 +08:00
const mapConfig = createMapConfig([{
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'
}
}]);
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);
});
});
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: {
query: 'select * from populated_places_simple_reduced'
}
},
radius: 60000
}
}]
});
const testClient = new TestClient(mapConfig, 1234);
testClient.getTile(0, 0, 0, {}, function (err, res, layergroup) {
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
});
});