2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 17:29:07 +08:00
|
|
|
require('../support/test-helper');
|
2015-04-28 00:02:15 +08:00
|
|
|
|
2015-01-26 22:51:10 +08:00
|
|
|
var assert = require('assert');
|
|
|
|
var RedisPool = require('redis-mpool');
|
2019-10-07 17:29:07 +08:00
|
|
|
var TemplateMaps = require('../../lib/backends/template-maps');
|
2015-01-26 22:51:10 +08:00
|
|
|
var _ = require('underscore');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('template_maps', function () {
|
|
|
|
var redisPool = new RedisPool(global.environment.redis);
|
|
|
|
var templateMaps = new TemplateMaps(redisPool);
|
2015-01-26 22:51:10 +08:00
|
|
|
|
|
|
|
var owner = 'me';
|
|
|
|
var templateName = 'wadus';
|
|
|
|
|
|
|
|
var defaultTemplate = {
|
2019-10-22 01:07:24 +08:00
|
|
|
version: '0.0.1',
|
2015-01-26 22:51:10 +08:00
|
|
|
name: templateName
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function makeTemplate (layers) {
|
2015-01-26 22:51:10 +08:00
|
|
|
var layergroup = {
|
|
|
|
layers: layers
|
|
|
|
};
|
|
|
|
return _.extend({}, defaultTemplate, {
|
|
|
|
layergroup: layergroup
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var layerWithMissingOptions = {};
|
|
|
|
var minimumValidLayer = {
|
|
|
|
options: {
|
|
|
|
sql: 'select 1 cartodb_id, null::geometry the_geom_webmercator',
|
|
|
|
cartocss: '#layer { marker-fill:blue; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
};
|
2015-01-26 22:51:10 +08:00
|
|
|
|
|
|
|
var testScenarios = [
|
|
|
|
{
|
|
|
|
desc: 'Missing layers array does not validate',
|
|
|
|
template: makeTemplate(),
|
|
|
|
expected: {
|
|
|
|
isValid: false,
|
|
|
|
message: 'Missing or empty layers array from layergroup config'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'Empty layers array does not validate',
|
|
|
|
template: makeTemplate([]),
|
|
|
|
expected: {
|
|
|
|
isValid: false,
|
|
|
|
message: 'Missing or empty layers array from layergroup config'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'Layer with missing options does not validate',
|
|
|
|
template: makeTemplate([
|
|
|
|
layerWithMissingOptions
|
|
|
|
]),
|
|
|
|
expected: {
|
|
|
|
isValid: false,
|
|
|
|
message: 'Missing `options` in layergroup config for layers: 0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'Multiple layers report invalid layer',
|
|
|
|
template: makeTemplate([
|
|
|
|
minimumValidLayer,
|
|
|
|
layerWithMissingOptions
|
|
|
|
]),
|
|
|
|
expected: {
|
|
|
|
isValid: false,
|
|
|
|
message: 'Missing `options` in layergroup config for layers: 1'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'default auth but specified placeholders',
|
|
|
|
template: makeTemplate([
|
|
|
|
minimumValidLayer
|
|
|
|
]),
|
|
|
|
expected: {
|
|
|
|
isValid: true,
|
|
|
|
message: ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testScenarios.forEach(function (testScenario) {
|
|
|
|
it(testScenario.desc, function (done) {
|
|
|
|
templateMaps.addTemplate(owner, testScenario.template, function (err) {
|
2015-01-26 22:51:10 +08:00
|
|
|
if (testScenario.expected.isValid) {
|
|
|
|
assert.ok(!err);
|
|
|
|
templateMaps.delTemplate(owner, templateName, done);
|
|
|
|
} else {
|
|
|
|
assert.ok(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(err.message, testScenario.expected.message);
|
2015-01-26 22:51:10 +08:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|