2019-01-03 15:23:22 +00:00
|
|
|
const rewire = require('rewire');
|
|
|
|
const should = require('should');
|
|
|
|
const _ = require('lodash');
|
2020-03-30 16:26:47 +01:00
|
|
|
const publicSettings = require('../../../../core/server/services/settings/public');
|
|
|
|
let cache = rewire('../../../../core/server/services/settings/cache');
|
2017-06-04 12:52:22 +02:00
|
|
|
|
|
|
|
should.equal(true, true);
|
|
|
|
|
|
|
|
describe('UNIT: settings cache', function () {
|
2019-01-03 15:23:22 +00:00
|
|
|
beforeEach(function () {
|
2020-03-30 16:26:47 +01:00
|
|
|
cache = rewire('../../../../core/server/services/settings/cache');
|
2019-01-03 15:23:22 +00:00
|
|
|
});
|
|
|
|
|
2017-06-04 12:52:22 +02:00
|
|
|
it('does not auto convert string into number', function () {
|
|
|
|
cache.set('key1', {value: '1'});
|
|
|
|
(typeof cache.get('key1')).should.eql('string');
|
|
|
|
});
|
|
|
|
|
2017-10-26 13:54:18 +02:00
|
|
|
it('does not auto convert string into number: float', function () {
|
|
|
|
cache.set('key1', {value: '1.4'});
|
|
|
|
(typeof cache.get('key1')).should.eql('string');
|
|
|
|
});
|
|
|
|
|
2017-06-04 12:52:22 +02:00
|
|
|
it('stringified JSON get\'s parsed', function () {
|
|
|
|
cache.set('key2', {value: '{"a":"1","b":"hallo","c":{"d":[]},"e":2}'});
|
|
|
|
(typeof cache.get('key2')).should.eql('object');
|
|
|
|
cache.get('key2').a.should.eql('1');
|
|
|
|
cache.get('key2').b.should.eql('hallo');
|
|
|
|
cache.get('key2').c.should.eql({d: []});
|
|
|
|
cache.get('key2').e.should.eql(2);
|
|
|
|
});
|
2019-01-03 15:23:22 +00:00
|
|
|
|
|
|
|
it('can get all values', function () {
|
|
|
|
cache.set('key1', {value: '1'});
|
|
|
|
cache.get('key1').should.eql('1');
|
|
|
|
cache.getAll().should.eql({key1: {value: '1'}});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly filters and formats public values', function () {
|
|
|
|
cache.set('key1', {value: 'something'});
|
|
|
|
cache.set('title', {value: 'hello world'});
|
|
|
|
cache.set('active_timezone', {value: 'PST'});
|
|
|
|
|
|
|
|
cache.getAll().should.eql({
|
|
|
|
key1: {value: 'something'},
|
|
|
|
title: {value: 'hello world'},
|
|
|
|
active_timezone: {value: 'PST'}
|
|
|
|
});
|
|
|
|
|
2019-01-07 13:35:51 +00:00
|
|
|
let values = _.zipObject(_.values(publicSettings), _.fill(Array(_.size(publicSettings)), null));
|
2019-01-03 15:23:22 +00:00
|
|
|
values.title = 'hello world';
|
|
|
|
values.timezone = 'PST';
|
|
|
|
|
|
|
|
cache.getPublic().should.eql(values);
|
|
|
|
});
|
2017-06-04 12:52:22 +02:00
|
|
|
});
|