Windshaft-cartodb/test/unit/valid-template-maps-test.js

105 lines
3.0 KiB
JavaScript
Raw Normal View History

'use strict';
2019-10-07 17:29:07 +08:00
require('../support/test-helper');
2015-04-28 00:02:15 +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');
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);
var owner = 'me';
var templateName = 'wadus';
var defaultTemplate = {
2019-10-22 01:07:24 +08:00
version: '0.0.1',
name: templateName
};
2019-10-22 01:07:24 +08:00
function makeTemplate (layers) {
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'
}
};
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) {
if (testScenario.expected.isValid) {
assert.ok(!err);
templateMaps.delTemplate(owner, templateName, done);
} else {
assert.ok(err);
assert.strictEqual(err.message, testScenario.expected.message);
done();
}
});
});
});
});