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');
|
|
|
|
|
2015-04-28 00:03:15 +08:00
|
|
|
describe('template_maps', function() {
|
2015-01-23 01:38:42 +08:00
|
|
|
|
|
|
|
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,
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
testScenarios.forEach(function(testScenario) {
|
2015-04-28 00:03:15 +08:00
|
|
|
it('adding template returns a new instance with ' + testScenario.desc, function(done) {
|
2015-01-23 01:38:42 +08:00
|
|
|
|
|
|
|
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.equal(template.name, templateName);
|
|
|
|
assert.deepEqual(template.auth, testScenario.expected.auth);
|
|
|
|
assert.deepEqual(template.placeholders, testScenario.expected.placeholders);
|
|
|
|
|
|
|
|
templateMaps.delTemplate(owner, templateName, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|