2020-07-29 18:38:59 +02:00
|
|
|
import * as configApi from './config';
|
2020-06-26 09:26:56 -04:00
|
|
|
|
2021-11-18 19:17:00 +01:00
|
|
|
describe('when working with site config', function () {
|
2020-06-26 09:26:56 -04:00
|
|
|
beforeEach(() => {
|
2020-07-29 18:38:59 +02:00
|
|
|
// Resets the site config to default config
|
|
|
|
configApi.setSiteConfig({});
|
2020-06-26 09:26:56 -04:00
|
|
|
});
|
2021-11-18 19:17:00 +01:00
|
|
|
it('should set site config and config properly', function () {
|
2020-06-26 09:26:56 -04:00
|
|
|
let config_0 = { foo: 'bar', bar: 0 };
|
|
|
|
configApi.setSiteConfig(config_0);
|
|
|
|
let config_1 = configApi.getSiteConfig();
|
|
|
|
let config_2 = configApi.getConfig();
|
|
|
|
expect(config_1.foo).toEqual(config_0.foo);
|
|
|
|
expect(config_1.bar).toEqual(config_0.bar);
|
|
|
|
expect(config_1).toEqual(config_2);
|
|
|
|
});
|
2021-11-18 19:17:00 +01:00
|
|
|
it('should respect secure keys when applying directives', function () {
|
|
|
|
let config_0 = {
|
|
|
|
foo: 'bar',
|
|
|
|
bar: 'cant-be-changed',
|
|
|
|
secure: [...configApi.defaultConfig.secure, 'bar'],
|
|
|
|
};
|
2020-06-26 09:26:56 -04:00
|
|
|
configApi.setSiteConfig(config_0);
|
2021-11-18 19:17:00 +01:00
|
|
|
const directive = { foo: 'baf', bar: 'should-not-be-allowed' };
|
|
|
|
const cfg = configApi.updateCurrentConfig(config_0, [directive]);
|
2020-07-29 18:38:59 +02:00
|
|
|
expect(cfg.foo).toEqual(directive.foo);
|
2021-11-18 19:17:00 +01:00
|
|
|
expect(cfg.bar).toBe(config_0.bar);
|
2020-06-26 09:26:56 -04:00
|
|
|
});
|
2021-11-18 19:17:00 +01:00
|
|
|
it('should set reset config properly', function () {
|
|
|
|
let config_0 = { foo: 'bar', bar: 0 };
|
2020-06-26 09:26:56 -04:00
|
|
|
configApi.setSiteConfig(config_0);
|
2021-11-18 19:17:00 +01:00
|
|
|
let config_1 = { foo: 'baf' };
|
2020-06-26 09:26:56 -04:00
|
|
|
configApi.setConfig(config_1);
|
|
|
|
let config_2 = configApi.getConfig();
|
|
|
|
expect(config_2.foo).toEqual(config_1.foo);
|
|
|
|
configApi.reset();
|
|
|
|
let config_3 = configApi.getConfig();
|
|
|
|
expect(config_3.foo).toEqual(config_0.foo);
|
|
|
|
let config_4 = configApi.getSiteConfig();
|
|
|
|
expect(config_4.foo).toEqual(config_0.foo);
|
|
|
|
});
|
2021-11-18 19:17:00 +01:00
|
|
|
it('should set global reset config properly', function () {
|
|
|
|
let config_0 = { foo: 'bar', bar: 0 };
|
2020-06-26 09:26:56 -04:00
|
|
|
configApi.setSiteConfig(config_0);
|
|
|
|
let config_1 = configApi.getSiteConfig();
|
|
|
|
expect(config_1.foo).toEqual(config_0.foo);
|
|
|
|
let config_2 = configApi.getConfig();
|
|
|
|
expect(config_2.foo).toEqual(config_0.foo);
|
2021-11-18 19:17:00 +01:00
|
|
|
configApi.setConfig({ foobar: 'bar0' });
|
2020-07-29 18:38:59 +02:00
|
|
|
let config_3 = configApi.getConfig();
|
|
|
|
expect(config_3.foobar).toEqual('bar0');
|
|
|
|
configApi.reset();
|
2020-06-26 09:26:56 -04:00
|
|
|
let config_4 = configApi.getConfig();
|
2020-07-29 18:38:59 +02:00
|
|
|
expect(config_4.foobar).toBeUndefined();
|
2020-06-26 09:26:56 -04:00
|
|
|
});
|
|
|
|
});
|