mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
bd597db829
- This is part of the quest to separate the frontend and server & get rid of all the places where there are cross-requires - At the moment the settings cache is one big shared cache used by the frontend and server liberally - This change doesn't really solve the fundamental problems, as we still depend on events, and requires from inside frontend - However it allows us to control the misuse slightly better by getting rid of restricted requires and turning on that eslint ruleset
100 lines
3.0 KiB
JavaScript
100 lines
3.0 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/shared/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;
|
|
});
|
|
});
|