0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -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:
Daniel Lockyer 2023-09-25 11:07:00 +02:00 committed by Daniel Lockyer
parent 1432c6f311
commit 49d36fc1a1
2 changed files with 40 additions and 3 deletions

View file

@ -62,6 +62,11 @@ module.exports.getAll = () => {
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';
return labs;

View file

@ -6,13 +6,14 @@ const labs = require('../../../core/shared/labs');
const settingsCache = require('../../../core/shared/settings-cache');
function expectedLabsObject(obj) {
const withGA = Object.assign({}, obj);
let enabledFlags = {};
labs.GA_KEYS.forEach((key) => {
withGA[key] = true;
enabledFlags[key] = true;
});
return withGA;
enabledFlags = Object.assign(enabledFlags, obj);
return enabledFlags;
}
describe('Labs Service', function () {
@ -64,6 +65,37 @@ describe('Labs Service', function () {
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 () {
sinon.stub(settingsCache, 'get');
settingsCache.get.withArgs('members_signup_access').returns('all');