0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added mockLabsDisabled to e2e framework

- Can now easily mock labs flags as enabled or disabled using mockManager
- Updated some bits of code that directly mocked labs
- Aside: improved error thrown when things go wrong booting Ghost
This commit is contained in:
Hannah Wolfe 2022-02-10 12:03:47 +00:00
parent a1edff4b0c
commit 83aa35241a
No known key found for this signature in database
GPG key ID: AB586C3B5AE5C037
4 changed files with 29 additions and 10 deletions

View file

@ -5,18 +5,19 @@ const sinon = require('sinon');
const testUtils = require('../../utils'); const testUtils = require('../../utils');
const localUtils = require('./utils'); const localUtils = require('./utils');
const config = require('../../../core/shared/config'); const config = require('../../../core/shared/config');
const labs = require('../../../core/shared/labs');
const Papa = require('papaparse'); const Papa = require('papaparse');
const {mockManager} = require('../../utils/e2e-framework');
describe('Members API', function () { describe('Members API', function () {
let request; let request;
beforeEach(function () { beforeEach(function () {
sinon.stub(labs, 'isSet').withArgs('multipleProducts').returns(false); mockManager.mockLabsDisabled('multipleProducts');
}); });
afterEach(function () { afterEach(function () {
sinon.restore(); mockManager.restore();
}); });
before(async function () { before(async function () {

View file

@ -1,8 +1,6 @@
const should = require('should'); const should = require('should');
const sinon = require('sinon');
const labs = require('../../../core/shared/labs');
const {agentProvider, fixtureManager} = require('../../utils/e2e-framework'); const {agentProvider, fixtureManager, mockManager} = require('../../utils/e2e-framework');
describe('Tiers API', function () { describe('Tiers API', function () {
let agent; let agent;
@ -14,13 +12,13 @@ describe('Tiers API', function () {
}); });
beforeEach(function () { beforeEach(function () {
sinon.stub(labs, 'isSet').withArgs('multipleProducts').returns(false); mockManager.mockLabsDisabled('multipleProducts');
const stripeService = require('../../../core/server/services/stripe'); const stripeService = require('../../../core/server/services/stripe');
stripeService.api._configured = true; stripeService.api._configured = true;
}); });
afterEach(function () { afterEach(function () {
sinon.restore(); mockManager.restore();
const stripeService = require('../../../core/server/services/stripe'); const stripeService = require('../../../core/server/services/stripe');
stripeService.api._configured = false; stripeService.api._configured = false;
}); });

View file

@ -28,7 +28,26 @@ const mockLabsEnabled = (flag, alpha = true) => {
configUtils.set('enableDeveloperExperiments', true); configUtils.set('enableDeveloperExperiments', true);
} }
mocks.labs[flag] = sinon.stub(labs, 'isSet').withArgs(flag).returns(true); if (mocks.labs[flag]) {
mocks.labs[flag].returns(true);
} else {
mocks.labs[flag] = sinon.stub(labs, 'isSet').withArgs(flag).returns(true);
}
};
const mockLabsDisabled = (flag, alpha = true) => {
mocks.labs = mocks.labs || {};
// We assume we should enable alpha experiments unless explicitly told not to!
if (!alpha) {
configUtils.set('enableDeveloperExperiments', true);
}
if (mocks.labs[flag]) {
mocks.labs[flag].returns(false);
} else {
mocks.labs[flag] = sinon.stub(labs, 'isSet').withArgs(flag).returns(false);
}
}; };
const sentEmailCount = (count) => { const sentEmailCount = (count) => {
@ -74,6 +93,7 @@ const restore = () => {
module.exports = { module.exports = {
mockMail, mockMail,
mockLabsEnabled, mockLabsEnabled,
mockLabsDisabled,
restore, restore,
assert: { assert: {
sentEmailCount, sentEmailCount,

View file

@ -129,7 +129,7 @@ const getAdminAPIAgent = async () => {
originURL originURL
}); });
} catch (error) { } catch (error) {
throw new Error('Unable to create test agent'); error.message = `Unable to create test agent. ${error.message}`;
} }
}; };