mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
d7ae6e0138
refs https://github.com/TryGhost/Team/issues/1107 - updated schema validation to allow `'image'` through as a known setting type now that Admin has support - added transformation of setting values for `'image'` types because they will be URLs and should be stored with `__GHOST_URL__`
64 lines
2.8 KiB
JavaScript
64 lines
2.8 KiB
JavaScript
const should = require('should');
|
|
const models = require('../../../../core/server/models');
|
|
|
|
describe('Unit: models/custom-theme-setting', function () {
|
|
before(function () {
|
|
models.init();
|
|
});
|
|
|
|
describe('parse', function () {
|
|
it('ensure correct parsing when fetching from db', function () {
|
|
const setting = models.CustomThemeSetting.forge();
|
|
|
|
let returns = setting.parse({theme: 'test', key: 'dark_mode', value: 'false', type: 'boolean'});
|
|
should.equal(returns.value, false);
|
|
|
|
returns = setting.parse({theme: 'test', key: 'dark_mode', value: false, type: 'boolean'});
|
|
should.equal(returns.value, false);
|
|
|
|
returns = setting.parse({theme: 'test', key: 'dark_mode', value: true, type: 'boolean'});
|
|
should.equal(returns.value, true);
|
|
|
|
returns = setting.parse({theme: 'test', key: 'dark_mode', value: 'true', type: 'boolean'});
|
|
should.equal(returns.value, true);
|
|
|
|
returns = setting.parse({theme: 'test', key: 'dark_mode', value: '0', type: 'boolean'});
|
|
should.equal(returns.value, false);
|
|
|
|
returns = setting.parse({theme: 'test', key: 'dark_mode', value: '1', type: 'boolean'});
|
|
should.equal(returns.value, true);
|
|
|
|
returns = setting.parse({theme: 'test', key: 'something', value: 'null', type: 'select'});
|
|
should.equal(returns.value, 'null');
|
|
|
|
returns = setting.parse({theme: 'test', key: 'something', value: '__GHOST_URL__/assets/image.jpg', type: 'image'});
|
|
should.equal(returns.value, 'http://127.0.0.1:2369/assets/image.jpg');
|
|
});
|
|
});
|
|
|
|
describe('format', function () {
|
|
it('ensure correct formatting when setting', function () {
|
|
const setting = models.CustomThemeSetting.forge();
|
|
|
|
let returns = setting.format({theme: 'test', key: 'dark_mode', value: '0', type: 'boolean'});
|
|
should.equal(returns.value, 'false');
|
|
|
|
returns = setting.format({theme: 'test', key: 'dark_mode', value: '1', type: 'boolean'});
|
|
should.equal(returns.value, 'true');
|
|
|
|
returns = setting.format({theme: 'test', key: 'dark_mode', value: 'false', type: 'boolean'});
|
|
should.equal(returns.value, 'false');
|
|
|
|
returns = setting.format({theme: 'test', key: 'dark_mode', value: 'true', type: 'boolean'});
|
|
should.equal(returns.value, 'true');
|
|
});
|
|
|
|
it('transforms urls when persisting to db', function () {
|
|
const setting = models.CustomThemeSetting.forge();
|
|
|
|
let returns = setting.formatOnWrite({theme: 'test', key: 'something', value: '/assets/image.jpg', type: 'image'});
|
|
should.equal(returns.value, '__GHOST_URL__/assets/image.jpg');
|
|
});
|
|
});
|
|
});
|