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:03:15 +08:00
|
|
|
|
2015-01-23 01:38:42 +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-23 01:38:42 +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-23 01:38:42 +08:00
|
|
|
|
|
|
|
var owner = 'me';
|
|
|
|
var templateName = 'wadus';
|
|
|
|
|
|
|
|
var defaultTemplate = {
|
2019-10-22 01:07:24 +08:00
|
|
|
version: '0.0.1',
|
2015-01-23 01:38:42 +08:00
|
|
|
name: templateName,
|
|
|
|
layergroup: {
|
2015-01-26 22:51:10 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select 1 cartodb_id, null::geometry the_geom_webmercator',
|
|
|
|
cartocss: '#layer { marker-fill:blue; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2015-01-23 01:38:42 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function makeTemplate (auth, placeholders) {
|
2015-01-23 01:38:42 +08:00
|
|
|
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) {
|
2015-01-23 01:38:42 +08:00
|
|
|
assert.ok(!err, 'Unexpected error adding template: ' + (err && err.message));
|
|
|
|
assert.ok(testScenario.template !== template, 'template instances should be different');
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(template.name, templateName);
|
2015-01-23 01:38:42 +08:00
|
|
|
assert.deepEqual(template.auth, testScenario.expected.auth);
|
|
|
|
assert.deepEqual(template.placeholders, testScenario.expected.placeholders);
|
|
|
|
|
|
|
|
templateMaps.delTemplate(owner, templateName, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|