Add missing test

This commit is contained in:
Daniel García Aubert 2019-07-04 12:24:42 +02:00
parent 50a35fa8c7
commit 9408be108b

View File

@ -0,0 +1,91 @@
'use strict';
const server = require('../../app/server')();
const assert = require('../support/assert');
const qs = require('querystring');
describe('cache headers', function () {
it('should return a Vary header', function (done) {
assert.response(server, {
url: `/api/v1/sql?${qs.encode({
api_key: '1234',
q: 'select * from untitle_table_4'
})}`,
headers: {
host: 'vizzuality.cartodb.com'
},
method: 'GET'
},
{},
function (err, res) {
assert.equal(res.headers.vary, 'Authorization');
done();
});
});
it('should return a proper max-age when he table is or isn\'t added to CDB_TableMetadata', function (done) {
const ONE_YEAR_IN_SECONDS = 60 * 60 * 24 * 365;
const noTtl = 0;
const fallbackTtl = global.settings.cache.fallbackTtl;
const ttl = global.settings.cache.ttl || ONE_YEAR_IN_SECONDS;
const tableName = `wadus_table_${Date.now()}`;
assert.response(server, {
url: `/api/v1/sql?${qs.encode({
api_key: '1234',
q: `create table ${tableName}()`
})}`,
headers: {
host: 'vizzuality.cartodb.com'
},
method: 'GET'
},
{},
function(err, res) {
assert.equal(res.headers['cache-control'], `no-cache,max-age=${noTtl},must-revalidate,public`);
assert.response(server, {
url: `/api/v1/sql?${qs.encode({
api_key: '1234',
q: `select * from ${tableName}`
})}`,
headers: {
host: 'vizzuality.cartodb.com'
},
method: 'GET'
}, {},
function(err, res) {
assert.equal(res.headers['cache-control'], `no-cache,max-age=${fallbackTtl},must-revalidate,public`);
assert.response(server, {
url: `/api/v1/sql?${qs.encode({
api_key: '1234',
q: `select CDB_TableMetadataTouch('${tableName}'::regclass)`
})}`,
headers: {
host: 'vizzuality.cartodb.com'
},
method: 'GET'
}, {},
function(err, res) {
assert.equal(res.headers['cache-control'], `no-cache,max-age=${ttl},must-revalidate,public`);
assert.response(server, {
url: `/api/v1/sql?${qs.encode({
api_key: '1234',
q: `select * from ${tableName}`
})}`,
headers: {
host: 'vizzuality.cartodb.com'
},
method: 'GET'
}, {},
function(err, res) {
assert.equal(res.headers['cache-control'], `no-cache,max-age=${ttl},must-revalidate,public`);
done();
});
});
});
});
});
});