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,32 +25,92 @@ describe('get requests x-cache-channel', function() {
status: 200 status: 200
}; };
var mapConfig = { var mapConfigs = [
version: '1.3.0', {
layers: [ "description": "header should be present",
"data":
{
version: '1.4.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": "source",
"params": {
"query": "select * from test_table limit 2"
}
}
]
},
},
{
"description": "header should be present and be composed with source table name",
"data":
{ {
options: { version: '1.5.0',
sql: 'select * from test_table limit 2', layers: [
cartocss: '#layer { marker-fill:red; }', {
cartocss_version: '2.3.0', options: {
attributes: { source: {
id:'cartodb_id', id: "2570e105-7b37-40d2-bdf4-1af889598745"
columns: [ },
'name', sql: 'select * from test_table limit 2',
'address' 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 {
method: 'GET', url: '/api/v1/map?api_key=1234&config=' + encodeURIComponent(JSON.stringify(mapConfig)),
headers: { method: 'GET',
host: 'localhost' headers: {
} host: 'localhost'
}
};
}; };
function getRequest(url, addApiKey, callbackName) { function getRequest(url, addApiKey, callbackName) {
@ -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,75 +178,76 @@ 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) {
var testFn = validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table');
withLayergroupId(mapConfig, function(err, layergroupId, res) {
testFn(res);
});
});
it('/api/v1/map Map instantiation', function(done) { it ('/api/v1/map/:token/:z/:x/:y@:scale_factor?x.:format Mapnik retina tiles', function(done) {
var testFn = validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table'); withLayergroupId(mapConfig, function(err, layergroupId) {
withLayergroupId(function(err, layergroupId, res) { assert.response(
testFn(res); server,
getRequest('/api/v1/map/' + layergroupId + '/0/0/0@2x.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/:token/:z/:x/:y@:scale_factor?x.:format Mapnik tiles', function(done) {
withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/' + layergroupId + '/0/0/0.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/:token/:layer/:z/:x/:y.(:format) Per :layer rendering', function(done) {
withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/' + layergroupId + '/0/0/0/0.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/:token/:layer/attributes/:fid endpoint for info windows', function(done) {
withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/' + layergroupId + '/0/attributes/1'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/static/center/:token/:z/:lat/:lng/:width/:height.:format static maps', function(done) {
withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/static/center/' + layergroupId + '/0/0/0/400/300.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/static/bbox/:token/:bbox/:width/:height.:format static maps', function(done) {
withLayergroupId(mapConfig, function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/static/bbox/' + layergroupId + '/-45,-45,45,45/400/300.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
}); });
}); });
it ('/api/v1/map/:token/:z/:x/:y@:scale_factor?x.:format Mapnik retina tiles', function(done) {
withLayergroupId(function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/' + layergroupId + '/0/0/0@2x.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/:token/:z/:x/:y@:scale_factor?x.:format Mapnik tiles', function(done) {
withLayergroupId(function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/' + layergroupId + '/0/0/0.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/:token/:layer/:z/:x/:y.(:format) Per :layer rendering', function(done) {
withLayergroupId(function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/' + layergroupId + '/0/0/0/0.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/:token/:layer/attributes/:fid endpoint for info windows', function(done) {
withLayergroupId(function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/' + layergroupId + '/0/attributes/1'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/static/center/:token/:z/:lat/:lng/:width/:height.:format static maps', function(done) {
withLayergroupId(function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/static/center/' + layergroupId + '/0/0/0/400/300.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
it ('/api/v1/map/static/bbox/:token/:bbox/:width/:height.:format static maps', function(done) {
withLayergroupId(function(err, layergroupId) {
assert.response(
server,
getRequest('/api/v1/map/static/bbox/' + layergroupId + '/-45,-45,45,45/400/300.png'),
validateXCacheChannel(done, 'test_windshaft_cartodb_user_1_db:public.test_table')
);
});
});
}); });
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)
); );
}); });
}); });
}); });
}); });