2019-11-06 10:42:39 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
|
2021-10-06 13:12:21 +03:00
|
|
|
const configUtils = require('../../../utils/configUtils');
|
|
|
|
const labs = require('../../../../core/shared/labs');
|
|
|
|
const settingsCache = require('../../../../core/shared/settings-cache');
|
2019-11-06 10:42:39 +03:00
|
|
|
|
2021-10-22 17:02:16 +03:00
|
|
|
function expectedLabsObject(obj) {
|
|
|
|
const withGA = Object.assign({}, obj);
|
|
|
|
|
|
|
|
labs.GA_KEYS.forEach((key) => {
|
|
|
|
withGA[key] = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return withGA;
|
|
|
|
}
|
|
|
|
|
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 () {
|
2021-10-22 17:02:16 +03:00
|
|
|
labs.getAll().should.eql(expectedLabsObject({
|
2021-06-07 19:51:37 +03:00
|
|
|
members: true
|
2021-10-22 17:02:16 +03:00
|
|
|
}));
|
2021-06-07 19:51:37 +03:00
|
|
|
});
|
|
|
|
|
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({
|
2021-10-07 13:08:56 +03:00
|
|
|
oauthLogin: true
|
2021-06-09 18:30:24 +03:00
|
|
|
});
|
|
|
|
|
2021-10-07 13:08:56 +03:00
|
|
|
// NOTE: this test should be rewritten to test the alpha flag independently of the internal ALPHA_FEATURES list
|
|
|
|
// otherwise we end up in the endless maintenance loop and need to update it every time a feature graduates from alpha
|
2021-10-22 17:02:16 +03:00
|
|
|
labs.getAll().should.eql(expectedLabsObject({
|
2021-10-07 13:08:56 +03:00
|
|
|
oauthLogin: true,
|
2021-06-09 18:30:24 +03:00
|
|
|
members: true
|
2021-10-22 17:02:16 +03:00
|
|
|
}));
|
2021-06-09 18:30:24 +03:00
|
|
|
|
|
|
|
labs.isSet('members').should.be.true;
|
2021-10-07 13:08:56 +03:00
|
|
|
labs.isSet('oauthLogin').should.be.true;
|
2021-06-09 18:30:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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({
|
2021-10-07 13:08:56 +03:00
|
|
|
oauthLogin: true
|
2021-06-09 18:30:24 +03:00
|
|
|
});
|
|
|
|
|
2021-10-07 13:08:56 +03:00
|
|
|
// NOTE: this test should be rewritten to test the alpha flag independently of the internal ALPHA_FEATURES list
|
|
|
|
// otherwise we end up in the endless maintenance loop and need to update it every time a feature graduates from alpha
|
2021-10-22 17:02:16 +03:00
|
|
|
labs.getAll().should.eql(expectedLabsObject({
|
2021-06-09 18:30:24 +03:00
|
|
|
members: true
|
2021-10-22 17:02:16 +03:00
|
|
|
}));
|
2021-06-09 18:30:24 +03:00
|
|
|
|
|
|
|
labs.isSet('members').should.be.true;
|
2021-10-07 13:08:56 +03:00
|
|
|
labs.isSet('oauthLogin').should.be.false;
|
2021-06-09 18:30:24 +03:00
|
|
|
});
|
|
|
|
|
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-10-22 17:02:16 +03:00
|
|
|
labs.getAll().should.eql(expectedLabsObject({
|
2021-02-17 02:24:54 +03:00
|
|
|
members: true
|
2021-10-22 17:02:16 +03:00
|
|
|
}));
|
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
|
|
|
|
});
|
|
|
|
|
2021-10-22 17:02:16 +03:00
|
|
|
labs.getAll().should.eql(expectedLabsObject({
|
2021-06-07 19:51:37 +03:00
|
|
|
members: true,
|
|
|
|
activitypub: false
|
2021-10-22 17:02:16 +03:00
|
|
|
}));
|
2021-06-07 19:51:37 +03:00
|
|
|
|
|
|
|
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');
|
|
|
|
|
2021-10-22 17:02:16 +03:00
|
|
|
labs.getAll().should.eql(expectedLabsObject({
|
2021-04-19 20:28:51 +03:00
|
|
|
members: false
|
2021-10-22 17:02:16 +03:00
|
|
|
}));
|
2021-04-19 20:28:51 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
});
|