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

105 lines
3.1 KiB
JavaScript
Raw Normal View History

'use strict';
2019-10-07 17:29:07 +08:00
require('../support/test-helper');
2015-04-28 00:03: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,
layergroup: {
layers: [
{
options: {
sql: 'select 1 cartodb_id, null::geometry the_geom_webmercator',
cartocss: '#layer { marker-fill:blue; }',
cartocss_version: '2.3.0'
}
}
]
}
};
2019-10-22 01:07:24 +08:00
function makeTemplate (auth, placeholders) {
return _.extend({}, defaultTemplate, {
auth: auth,
placeholders: placeholders
});
}
var defaultAuth = {
method: 'open'
};
var authTokenSample = {
method: 'token',
valid_tokens: ['wadus_token']
};
var placeholdersSample = {
wadus: {
type: 'number',
default: 1
}
};
var testScenarios = [
{
desc: 'default auth and placeholders values',
template: defaultTemplate,
expected: {
auth: defaultAuth,
placeholders: {}
}
},
{
desc: 'default placeholders but specified auth',
template: makeTemplate(authTokenSample),
expected: {
auth: authTokenSample,
placeholders: {}
}
},
{
desc: 'default auth but specified placeholders',
template: makeTemplate(undefined, placeholdersSample),
expected: {
auth: defaultAuth,
placeholders: placeholdersSample
}
},
{
desc: 'specified auth and placeholders',
template: makeTemplate(authTokenSample, placeholdersSample),
expected: {
auth: authTokenSample,
placeholders: placeholdersSample
}
}
];
2019-10-22 01:07:24 +08:00
testScenarios.forEach(function (testScenario) {
it('adding template returns a new instance with ' + testScenario.desc, function (done) {
templateMaps.addTemplate(owner, testScenario.template, function (err, templateId, template) {
assert.ok(!err, 'Unexpected error adding template: ' + (err && err.message));
assert.ok(testScenario.template !== template, 'template instances should be different');
assert.strictEqual(template.name, templateName);
assert.deepEqual(template.auth, testScenario.expected.auth);
assert.deepEqual(template.placeholders, testScenario.expected.placeholders);
templateMaps.delTemplate(owner, templateName, done);
});
});
});
});