2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2016-01-12 22:53:16 +08:00
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
var redis = require('redis');
|
|
|
|
var RedisPool = require('redis-mpool');
|
2019-10-07 16:50:14 +08:00
|
|
|
var TemplateMaps = require('../../lib/backends/template-maps');
|
2016-01-12 22:53:16 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('TemplateMaps limits', function () {
|
2016-01-12 22:53:16 +08:00
|
|
|
var OWNER = 'username';
|
|
|
|
var templateCounter = 0;
|
2019-10-22 01:07:24 +08:00
|
|
|
function templateUniqueName () {
|
2016-01-12 22:53:16 +08:00
|
|
|
return 'tpl_' + templateCounter++;
|
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
function createTemplate () {
|
2016-01-12 22:53:16 +08:00
|
|
|
return {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: templateUniqueName(),
|
|
|
|
layergroup: {
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'plain',
|
|
|
|
options: {
|
|
|
|
color: 'blue'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var redisClient = redis.createClient(global.environment.redis.port);
|
|
|
|
var redisPool = new RedisPool(global.environment.redis);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
afterEach(function (done) {
|
2016-01-12 22:53:16 +08:00
|
|
|
redisClient.del('map_tpl|' + OWNER, done);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should allow to create templates when there is no limit in options', function (done) {
|
2016-01-12 22:53:16 +08:00
|
|
|
var templateMaps = new TemplateMaps(redisPool);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
templateMaps.addTemplate(OWNER, createTemplate(), function (err, templateName, template) {
|
2016-01-12 22:53:16 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.ok(template);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
templateMaps.addTemplate(OWNER, createTemplate(), function (err, templateName, template) {
|
2016-01-12 22:53:16 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.ok(template);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should allow to create templates with limit in options', function (done) {
|
|
|
|
var templateMaps = new TemplateMaps(redisPool, { max_user_templates: 1 });
|
2016-01-12 22:53:16 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
templateMaps.addTemplate(OWNER, createTemplate(), function (err, templateName, template) {
|
2016-01-12 22:53:16 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.ok(template);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should fail to create more templates than allowed by options', function (done) {
|
|
|
|
var templateMaps = new TemplateMaps(redisPool, { max_user_templates: 1 });
|
2016-01-12 22:53:16 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
templateMaps.addTemplate(OWNER, createTemplate(), function (err, templateName, template) {
|
2016-01-12 22:53:16 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.ok(template);
|
2019-10-22 01:07:24 +08:00
|
|
|
templateMaps.addTemplate(OWNER, createTemplate(), function (err) {
|
2016-01-12 22:53:16 +08:00
|
|
|
assert.ok(err);
|
|
|
|
assert.equal(err.http_status, 409);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|