mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Allowed config to override labs flags
fixes https://github.com/TryGhost/DevOps/issues/72 - in order to have greater control of labs flags outside of Ghost, this commit allows Ghost to respect the value of `labs: { flagName: boolean }` - this means we can hardcode a value to true or false, irrespective of the value in the DB or GA flags array - also adds tests to check functionality
This commit is contained in:
parent
1432c6f311
commit
49d36fc1a1
2 changed files with 40 additions and 3 deletions
|
@ -62,6 +62,11 @@ module.exports.getAll = () => {
|
||||||
labs[gaKey] = true;
|
labs[gaKey] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const labsConfig = config.get('labs') || {};
|
||||||
|
Object.keys(labsConfig).forEach((key) => {
|
||||||
|
labs[key] = labsConfig[key];
|
||||||
|
});
|
||||||
|
|
||||||
labs.members = settingsCache.get('members_signup_access') !== 'none';
|
labs.members = settingsCache.get('members_signup_access') !== 'none';
|
||||||
|
|
||||||
return labs;
|
return labs;
|
||||||
|
|
|
@ -6,13 +6,14 @@ const labs = require('../../../core/shared/labs');
|
||||||
const settingsCache = require('../../../core/shared/settings-cache');
|
const settingsCache = require('../../../core/shared/settings-cache');
|
||||||
|
|
||||||
function expectedLabsObject(obj) {
|
function expectedLabsObject(obj) {
|
||||||
const withGA = Object.assign({}, obj);
|
let enabledFlags = {};
|
||||||
|
|
||||||
labs.GA_KEYS.forEach((key) => {
|
labs.GA_KEYS.forEach((key) => {
|
||||||
withGA[key] = true;
|
enabledFlags[key] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
return withGA;
|
enabledFlags = Object.assign(enabledFlags, obj);
|
||||||
|
return enabledFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Labs Service', function () {
|
describe('Labs Service', function () {
|
||||||
|
@ -64,6 +65,37 @@ describe('Labs Service', function () {
|
||||||
assert.equal(labs.isSet('urlCache'), false);
|
assert.equal(labs.isSet('urlCache'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('respects the value in config over settings', function () {
|
||||||
|
configUtils.set('labs', {
|
||||||
|
collections: false
|
||||||
|
});
|
||||||
|
sinon.stub(settingsCache, 'get');
|
||||||
|
settingsCache.get.withArgs('labs').returns({
|
||||||
|
collections: true,
|
||||||
|
members: true
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(labs.getAll(), expectedLabsObject({
|
||||||
|
collections: false,
|
||||||
|
members: true
|
||||||
|
}));
|
||||||
|
|
||||||
|
assert.equal(labs.isSet('collections'), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('respects the value in config over GA keys', function () {
|
||||||
|
configUtils.set('labs', {
|
||||||
|
audienceFeedback: false
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(labs.getAll(), expectedLabsObject({
|
||||||
|
audienceFeedback: false,
|
||||||
|
members: true
|
||||||
|
}));
|
||||||
|
|
||||||
|
assert.equal(labs.isSet('audienceFeedback'), false);
|
||||||
|
});
|
||||||
|
|
||||||
it('members flag is true when members_signup_access setting is "all"', function () {
|
it('members flag is true when members_signup_access setting is "all"', function () {
|
||||||
sinon.stub(settingsCache, 'get');
|
sinon.stub(settingsCache, 'get');
|
||||||
settingsCache.get.withArgs('members_signup_access').returns('all');
|
settingsCache.get.withArgs('members_signup_access').returns('all');
|
||||||
|
|
Loading…
Add table
Reference in a new issue