diff --git a/core/server/data/schema/schema.js b/core/server/data/schema/schema.js index 5fc2bea2eb..0bbbd65b96 100644 --- a/core/server/data/schema/schema.js +++ b/core/server/data/schema/schema.js @@ -187,7 +187,8 @@ module.exports = { 'array', 'string', 'number', - 'boolean' + 'boolean', + 'object' ]] } }, diff --git a/core/server/services/labs.js b/core/server/services/labs.js index 5a799f9d6a..dddbd82c31 100644 --- a/core/server/services/labs.js +++ b/core/server/services/labs.js @@ -24,7 +24,7 @@ module.exports.getAll = () => { const labs = _.cloneDeep(settingsCache.get('labs')) || {}; ALPHA_FEATURES.forEach((alphaKey) => { - if (labs[alphaKey] && !(config.get('enableDeveloperExperiments'))) { + if (labs[alphaKey] && !(config.get('enableDeveloperExperiments') || process.env.NODE_ENV.match(/^testing/))) { delete labs[alphaKey]; } }); diff --git a/test/regression/api/canary/admin/settings_spec.js b/test/regression/api/canary/admin/settings_spec.js index 0b301450a7..265a6529b1 100644 --- a/test/regression/api/canary/admin/settings_spec.js +++ b/test/regression/api/canary/admin/settings_spec.js @@ -677,8 +677,10 @@ describe('Settings API (canary)', function () { jsonResponse.settings.length.should.eql(1); testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']); + + const jsonObjectRegex = /^\{.*\}$/; // '{...}' jsonResponse.settings[0].key.should.eql('labs'); - jsonResponse.settings[0].value.should.eql(JSON.stringify({})); + jsonResponse.settings[0].value.should.match(jsonObjectRegex); }); it('Can read deprecated default_locale', function (done) { diff --git a/test/regression/api/v2/admin/settings_spec.js b/test/regression/api/v2/admin/settings_spec.js index 318e0e8e8f..d9321e9d88 100644 --- a/test/regression/api/v2/admin/settings_spec.js +++ b/test/regression/api/v2/admin/settings_spec.js @@ -286,8 +286,10 @@ describe('Settings API (v2)', function () { jsonResponse.settings.length.should.eql(1); testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']); + + const jsonObjectRegex = /^\{.*\}$/; // '{...}' jsonResponse.settings[0].key.should.eql('labs'); - jsonResponse.settings[0].value.should.eql(JSON.stringify({})); + jsonResponse.settings[0].value.should.match(jsonObjectRegex); }); it('Can read default_locale deprecated in v3', function (done) { diff --git a/test/regression/api/v3/admin/settings_spec.js b/test/regression/api/v3/admin/settings_spec.js index 63d3ef9de7..bf446c3545 100644 --- a/test/regression/api/v3/admin/settings_spec.js +++ b/test/regression/api/v3/admin/settings_spec.js @@ -303,8 +303,10 @@ describe('Settings API (v3)', function () { jsonResponse.settings.length.should.eql(1); testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']); + + const jsonObjectRegex = /^\{.*\}$/; // '{...}' jsonResponse.settings[0].key.should.eql('labs'); - jsonResponse.settings[0].value.should.eql(JSON.stringify({})); + jsonResponse.settings[0].value.should.match(jsonObjectRegex); }); it('Can read deprecated default_locale', function (done) { diff --git a/test/unit/services/labs_spec.js b/test/unit/services/labs_spec.js index 36567fd882..996b04f7f9 100644 --- a/test/unit/services/labs_spec.js +++ b/test/unit/services/labs_spec.js @@ -19,6 +19,7 @@ describe('Labs Service', function () { 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 @@ -35,6 +36,7 @@ describe('Labs Service', function () { 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 diff --git a/test/utils/fixture-utils.js b/test/utils/fixture-utils.js index c16c66c2b5..d8c2b251de 100644 --- a/test/utils/fixture-utils.js +++ b/test/utils/fixture-utils.js @@ -15,6 +15,7 @@ const emailAnalyticsService = require('../../core/server/services/email-analytic const permissions = require('../../core/server/services/permissions'); const settingsService = require('../../core/server/services/settings'); const settingsCache = require('../../core/server/services/settings/cache'); +const labsService = require('../../core/server/services/labs'); // Other Test Utilities const context = require('./fixtures/context'); @@ -536,6 +537,28 @@ const fixtures = { return Promise.map(DataGenerator.forKnex.snippets, function (snippet) { return models.Snippet.add(snippet, context.internal); }); + }, + + async enableAllLabsFeatures() { + const labsValue = Object.fromEntries(labsService.WRITABLE_KEYS_ALLOWLIST.map(key => [key, true])); + const labsSetting = DataGenerator.forKnex.createSetting({ + key: 'labs', + group: 'labs', + type: 'object', + value: JSON.stringify(labsValue) + }); + + const existingLabsSetting = await models.Settings.findOne({key: 'labs'}); + + if (existingLabsSetting) { + delete labsSetting.id; + await models.Settings.edit(labsSetting); + } else { + await models.Settings.add(labsSetting); + } + + settingsCache.shutdown(); + await settingsService.init(); } }; @@ -624,6 +647,9 @@ const toDoList = { }, snippets: function insertSnippets() { return fixtures.insertSnippets(); + }, + 'labs:enabled': function enableAllLabsFeatures() { + return fixtures.enableAllLabsFeatures(); } }; @@ -660,6 +686,8 @@ const getFixtureOps = (toDos) => { delete toDos.init; } + fixtureOps.push(toDoList['labs:enabled']); + // Go through our list of things to do, and add them to an array _.each(toDos, function (value, toDo) { let tmp;