Ghost/test/unit/services/labs_spec.js
Kevin Ansfield f49f7699aa
Enabled all labs flags when testing (#13036)
no issue

Shows impact of new code behind labs flags through the existing acceptance/regression tests. Allows for existing tests to be updated to match new behaviour rather than requiring separate tests where individual flags are enabled. Should result in minimal test updating once code reaches GA.

- adds a forced `'labs:enabled'` fixture op that edits the `labs` setting to enable all flags then restarts the settings service to pick up the new setting
- modifies labs service to not remove ALPHA_FEATURE labs settings when running in a testing environment
2021-06-10 12:54:34 +01:00

100 lines
3.1 KiB
JavaScript

const should = require('should');
const sinon = require('sinon');
const configUtils = require('../../utils/configUtils');
const labs = require('../../../core/server/services/labs');
const settingsCache = require('../../../core/server/services/settings/cache');
describe('Labs Service', function () {
afterEach(function () {
sinon.restore();
configUtils.restore();
});
it('can getAll, even if empty with enabled members', function () {
labs.getAll().should.eql({
members: true
});
});
it('returns an alpha flag when dev experiments in toggled', function () {
configUtils.set('enableDeveloperExperiments', true);
sinon.stub(process.env, 'NODE_ENV').value('production');
sinon.stub(settingsCache, 'get');
settingsCache.get.withArgs('labs').returns({
multipleProducts: true
});
labs.getAll().should.eql({
multipleProducts: true,
members: true
});
labs.isSet('members').should.be.true;
labs.isSet('multipleProducts').should.be.true;
});
it('returns a falsy alpha flag when dev experiments in NOT toggled', function () {
configUtils.set('enableDeveloperExperiments', false);
sinon.stub(process.env, 'NODE_ENV').value('production');
sinon.stub(settingsCache, 'get');
settingsCache.get.withArgs('labs').returns({
multipleProducts: true
});
labs.getAll().should.eql({
members: true
});
labs.isSet('members').should.be.true;
labs.isSet('multipleProducts').should.be.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');
labs.getAll().should.eql({
members: true
});
labs.isSet('members').should.be.true;
});
it('returns other allowlisted flags along with members', function () {
sinon.stub(settingsCache, 'get');
settingsCache.get.withArgs('members_signup_access').returns('all');
settingsCache.get.withArgs('labs').returns({
activitypub: false
});
labs.getAll().should.eql({
members: true,
activitypub: false
});
labs.isSet('members').should.be.true;
labs.isSet('activitypub').should.be.false;
});
it('members flag is false when members_signup_access setting is "none"', function () {
sinon.stub(settingsCache, 'get');
settingsCache.get.withArgs('members_signup_access').returns('none');
labs.getAll().should.eql({
members: false
});
labs.isSet('members').should.be.false;
});
it('isSet returns false for undefined', function () {
labs.isSet('bar').should.be.false;
});
it('isSet always returns false for deprecated', function () {
labs.isSet('subscribers').should.be.false;
labs.isSet('publicAPI').should.be.false;
});
});