From 2e8a5d0d86d60d90ca2164bdddf2849272d58783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 4 Jul 2019 15:34:37 +0200 Subject: [PATCH] Add test --- test/acceptance/cache/cache-control-header.js | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 test/acceptance/cache/cache-control-header.js diff --git a/test/acceptance/cache/cache-control-header.js b/test/acceptance/cache/cache-control-header.js new file mode 100644 index 00000000..f318214d --- /dev/null +++ b/test/acceptance/cache/cache-control-header.js @@ -0,0 +1,91 @@ +'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' + } +}]; + +function createMapConfig (layers = defaultLayers) { + return { + version: '1.8.0', + layers: layers + }; +} + +describe('cache-control header', function () { + describe('max-age directive', function () { + it('tile from a table wich is included in cdb_tablemetada', function (done) { + 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); + }); + }); + + it('tile from a table wich is NOT included in cdb_tablemetada', function (done) { + 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); + }); + }); + + it('tile from a dynamic query which doesn\'t use a table' , function (done) { + const ttl = global.environment.varnish.fallbackTtl || FIVE_MINUTES_IN_SECONDS; + 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); + }); + }); + }); +});