mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added test coverage to settings bread service
no issue - This serivce was missing any unit test coverage. Covering few cases gives a good groundwork to expand on
This commit is contained in:
parent
2d92e98392
commit
2a592a9bf3
1 changed files with 112 additions and 0 deletions
|
@ -0,0 +1,112 @@
|
||||||
|
const sinon = require('sinon');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const SettingsBreadService = require('../../../../../core/server/services/settings/settings-bread-service');
|
||||||
|
|
||||||
|
describe('UNIT > Settings BREAD Service:', function () {
|
||||||
|
afterEach(function () {
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('read', function () {
|
||||||
|
it('returns the setting ', async function () {
|
||||||
|
const defaultSettingsManager = new SettingsBreadService({
|
||||||
|
SettingsModel: {},
|
||||||
|
settingsCache: {
|
||||||
|
get: sinon
|
||||||
|
.stub()
|
||||||
|
.withArgs('version_notifications', {resolve: false})
|
||||||
|
.returns({
|
||||||
|
key: 'portal_button_signup_text',
|
||||||
|
value: 'Subscribe',
|
||||||
|
group: 'portal'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
labsService: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const setting = await defaultSettingsManager.read('version_notifications');
|
||||||
|
|
||||||
|
assert.deepEqual(setting, {
|
||||||
|
version_notifications: {
|
||||||
|
key: 'portal_button_signup_text',
|
||||||
|
value: 'Subscribe',
|
||||||
|
group: 'portal'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can read core group with internal context', async function () {
|
||||||
|
const defaultSettingsManager = new SettingsBreadService({
|
||||||
|
SettingsModel: {},
|
||||||
|
settingsCache: {
|
||||||
|
get: sinon
|
||||||
|
.stub()
|
||||||
|
.withArgs('version_notifications', {resolve: false})
|
||||||
|
.returns({
|
||||||
|
key: 'version_notifications',
|
||||||
|
value: '[\'4.0\']',
|
||||||
|
group: 'core'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
labsService: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const setting = await defaultSettingsManager.read('version_notifications', {internal: true});
|
||||||
|
|
||||||
|
assert.deepEqual(setting, {
|
||||||
|
version_notifications: {
|
||||||
|
group: 'core',
|
||||||
|
key: 'version_notifications',
|
||||||
|
value: '[\'4.0\']'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws and error when reading a core group without internal context', async function () {
|
||||||
|
const defaultSettingsManager = new SettingsBreadService({
|
||||||
|
SettingsModel: {},
|
||||||
|
settingsCache: {
|
||||||
|
get: sinon
|
||||||
|
.stub()
|
||||||
|
.withArgs('version_notifications', {resolve: false})
|
||||||
|
.returns({
|
||||||
|
key: 'version_notifications',
|
||||||
|
value: '[\'4.0\']',
|
||||||
|
group: 'core'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
labsService: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await defaultSettingsManager.read('version_notifications');
|
||||||
|
throw ('above line should have thrown');
|
||||||
|
} catch (error) {
|
||||||
|
assert.equal(error.errorType, 'NoPermissionError');
|
||||||
|
assert.equal(error.message, 'Attempted to access core setting from external request');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws an error when reading unknown setting', async function () {
|
||||||
|
const defaultSettingsManager = new SettingsBreadService({
|
||||||
|
SettingsModel: {},
|
||||||
|
settingsCache: {
|
||||||
|
get: sinon
|
||||||
|
.stub()
|
||||||
|
.withArgs('unknown_setting', {resolve: false})
|
||||||
|
.returns(null)
|
||||||
|
},
|
||||||
|
labsService: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await defaultSettingsManager.read('unknown_setting');
|
||||||
|
throw ('above line should have thrown');
|
||||||
|
} catch (error) {
|
||||||
|
assert.equal(error.errorType, 'NotFoundError');
|
||||||
|
assert.equal(error.message, 'Problem finding setting: unknown_setting');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue