Add more tests for x-cache-channel but with analysis

This commit is contained in:
Mario de Frutos 2017-03-10 17:22:07 +01:00
parent 5e4d1d5c1c
commit 0c387cf6d9

View File

@ -25,11 +25,18 @@ describe('get requests x-cache-channel', function() {
status: 200 status: 200
}; };
var mapConfig = { var mapConfigs = [
version: '1.3.0', {
"description": "header should be present",
"data":
{
version: '1.4.0',
layers: [ layers: [
{ {
options: { options: {
source: {
id: "2570e105-7b37-40d2-bdf4-1af889598745"
},
sql: 'select * from test_table limit 2', sql: 'select * from test_table limit 2',
cartocss: '#layer { marker-fill:red; }', cartocss: '#layer { marker-fill:red; }',
cartocss_version: '2.3.0', cartocss_version: '2.3.0',
@ -42,16 +49,69 @@ describe('get requests x-cache-channel', function() {
} }
} }
} }
],
analyses: [
{
"id": "2570e105-7b37-40d2-bdf4-1af889598745",
"type": "source",
"params": {
"query": "select * from test_table limit 2"
}
}
] ]
}; },
},
{
"description": "header should be present and be composed with source table name",
"data":
{
version: '1.5.0',
layers: [
{
options: {
source: {
id: "2570e105-7b37-40d2-bdf4-1af889598745"
},
sql: 'select * from test_table limit 2',
cartocss: '#layer { marker-fill:red; }',
cartocss_version: '2.3.0',
attributes: {
id:'cartodb_id',
columns: [
'name',
'address'
]
}
}
}
],
analyses: [
{
"id": "2570e105-7b37-40d2-bdf4-1af889598745",
"type": "buffer",
"params": {
"source": {
"type": "source",
"params": {
"query": "select * from test_table limit 2"
}
},
"radius": 50000
}
}
]
}
}];
var layergroupRequest = { var layergroupRequest = function(mapConfig) {
url: '/api/v1/map?config=' + encodeURIComponent(JSON.stringify(mapConfig)), return {
url: '/api/v1/map?api_key=1234&config=' + encodeURIComponent(JSON.stringify(mapConfig)),
method: 'GET', method: 'GET',
headers: { headers: {
host: 'localhost' host: 'localhost'
} }
}; };
};
function getRequest(url, addApiKey, callbackName) { function getRequest(url, addApiKey, callbackName) {
var params = {}; var params = {};
@ -101,10 +161,10 @@ describe('get requests x-cache-channel', function() {
}; };
} }
function withLayergroupId(callback) { function withLayergroupId(mapConfig, callback) {
assert.response( assert.response(
server, server,
layergroupRequest, layergroupRequest(mapConfig),
statusOkResponse, statusOkResponse,
function(res, err) { function(res, err) {
if (err) { if (err) {
@ -118,17 +178,18 @@ describe('get requests x-cache-channel', function() {
); );
} }
describe('header should be present', function() { mapConfigs.forEach(function(mapConfigData) {
describe(mapConfigData.description, function() {
var mapConfig = mapConfigData.data;
it('/api/v1/map Map instantiation', function(done) { it('/api/v1/map Map instantiation', function(done) {
var testFn = validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table'); var testFn = validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table');
withLayergroupId(function(err, layergroupId, res) { withLayergroupId(mapConfig, function(err, layergroupId, res) {
testFn(res); testFn(res);
}); });
}); });
it ('/api/v1/map/:token/:z/:x/:y@:scale_factor?x.:format Mapnik retina tiles', function(done) { it ('/api/v1/map/:token/:z/:x/:y@:scale_factor?x.:format Mapnik retina tiles', function(done) {
withLayergroupId(function(err, layergroupId) { withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response( assert.response(
server, server,
getRequest('/api/v1/map/' + layergroupId + '/0/0/0@2x.png'), getRequest('/api/v1/map/' + layergroupId + '/0/0/0@2x.png'),
@ -138,7 +199,7 @@ describe('get requests x-cache-channel', function() {
}); });
it ('/api/v1/map/:token/:z/:x/:y@:scale_factor?x.:format Mapnik tiles', function(done) { it ('/api/v1/map/:token/:z/:x/:y@:scale_factor?x.:format Mapnik tiles', function(done) {
withLayergroupId(function(err, layergroupId) { withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response( assert.response(
server, server,
getRequest('/api/v1/map/' + layergroupId + '/0/0/0.png'), getRequest('/api/v1/map/' + layergroupId + '/0/0/0.png'),
@ -148,7 +209,7 @@ describe('get requests x-cache-channel', function() {
}); });
it ('/api/v1/map/:token/:layer/:z/:x/:y.(:format) Per :layer rendering', function(done) { it ('/api/v1/map/:token/:layer/:z/:x/:y.(:format) Per :layer rendering', function(done) {
withLayergroupId(function(err, layergroupId) { withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response( assert.response(
server, server,
getRequest('/api/v1/map/' + layergroupId + '/0/0/0/0.png'), getRequest('/api/v1/map/' + layergroupId + '/0/0/0/0.png'),
@ -158,7 +219,7 @@ describe('get requests x-cache-channel', function() {
}); });
it ('/api/v1/map/:token/:layer/attributes/:fid endpoint for info windows', function(done) { it ('/api/v1/map/:token/:layer/attributes/:fid endpoint for info windows', function(done) {
withLayergroupId(function(err, layergroupId) { withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response( assert.response(
server, server,
getRequest('/api/v1/map/' + layergroupId + '/0/attributes/1'), getRequest('/api/v1/map/' + layergroupId + '/0/attributes/1'),
@ -168,7 +229,7 @@ describe('get requests x-cache-channel', function() {
}); });
it ('/api/v1/map/static/center/:token/:z/:lat/:lng/:width/:height.:format static maps', function(done) { it ('/api/v1/map/static/center/:token/:z/:lat/:lng/:width/:height.:format static maps', function(done) {
withLayergroupId(function(err, layergroupId) { withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response( assert.response(
server, server,
getRequest('/api/v1/map/static/center/' + layergroupId + '/0/0/0/400/300.png'), getRequest('/api/v1/map/static/center/' + layergroupId + '/0/0/0/400/300.png'),
@ -178,7 +239,7 @@ describe('get requests x-cache-channel', function() {
}); });
it ('/api/v1/map/static/bbox/:token/:bbox/:width/:height.:format static maps', function(done) { it ('/api/v1/map/static/bbox/:token/:bbox/:width/:height.:format static maps', function(done) {
withLayergroupId(function(err, layergroupId) { withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response( assert.response(
server, server,
getRequest('/api/v1/map/static/bbox/' + layergroupId + '/-45,-45,45,45/400/300.png'), getRequest('/api/v1/map/static/bbox/' + layergroupId + '/-45,-45,45,45/400/300.png'),
@ -186,7 +247,7 @@ describe('get requests x-cache-channel', function() {
); );
}); });
}); });
});
}); });
describe('header should NOT be present', function() { describe('header should NOT be present', function() {
@ -238,7 +299,7 @@ describe('get requests x-cache-channel', function() {
auth: { auth: {
method: 'open' method: 'open'
}, },
layergroup: mapConfig layergroup: mapConfigs[0].data
}; };
var namedMapRequest = { var namedMapRequest = {
@ -298,10 +359,6 @@ describe('get requests x-cache-channel', function() {
noXCacheChannelHeader(done) noXCacheChannelHeader(done)
); );
}); });
}); });
}); });
}); });