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

116 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');
2015-04-28 00:02:15 +08:00
describe('template_maps', function() {
var redisPool = new RedisPool(global.environment.redis),
templateMaps = new TemplateMaps(redisPool);
var owner = 'me';
var templateName = 'wadus';
var defaultTemplate = {
version:'0.0.1',
name: templateName
};
function makeTemplate(layers) {
var layergroup = {
layers: layers
};
return _.extend({}, defaultTemplate, {
layergroup: layergroup
});
}
var layerWithMissingOptions = {},
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: ''
}
}
];
testScenarios.forEach(function(testScenario) {
2015-04-28 00:02:15 +08:00
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.equal(err.message, testScenario.expected.message);
done();
}
});
});
});
});