2019-11-06 10:42:39 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
|
2021-06-09 18:30:24 +03:00
|
|
|
const configUtils = require('../../utils/configUtils');
|
2020-03-30 18:26:47 +03:00
|
|
|
const labs = require('../../../core/server/services/labs');
|
2021-04-19 20:28:51 +03:00
|
|
|
const settingsCache = require('../../../core/server/services/settings/cache');
|
2019-11-06 10:42:39 +03:00
|
|
|
|
|
|
|
describe('Labs Service', function () {
|
|
|
|
afterEach(function () {
|
|
|
|
sinon.restore();
|
2021-06-09 18:30:24 +03:00
|
|
|
configUtils.restore();
|
2019-11-06 10:42:39 +03:00
|
|
|
});
|
|
|
|
|
2021-06-07 19:51:37 +03:00
|
|
|
it('can getAll, even if empty with enabled members', function () {
|
|
|
|
labs.getAll().should.eql({
|
|
|
|
members: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-09 18:30:24 +03:00
|
|
|
it('returns an alpha flag when dev experiments in toggled', function () {
|
|
|
|
configUtils.set('enableDeveloperExperiments', true);
|
2021-06-10 14:54:34 +03:00
|
|
|
sinon.stub(process.env, 'NODE_ENV').value('production');
|
2021-06-09 18:30:24 +03:00
|
|
|
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);
|
2021-06-10 14:54:34 +03:00
|
|
|
sinon.stub(process.env, 'NODE_ENV').value('production');
|
2021-06-09 18:30:24 +03:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2021-04-19 20:28:51 +03:00
|
|
|
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');
|
|
|
|
|
2021-02-17 02:24:54 +03:00
|
|
|
labs.getAll().should.eql({
|
|
|
|
members: true
|
|
|
|
});
|
2019-11-06 10:42:39 +03:00
|
|
|
|
2021-02-17 02:24:54 +03:00
|
|
|
labs.isSet('members').should.be.true;
|
2019-11-06 10:42:39 +03:00
|
|
|
});
|
|
|
|
|
2021-06-07 19:51:37 +03:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2021-04-19 20:28:51 +03:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2019-11-06 10:42:39 +03:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
});
|