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 localUtils = require('./utils');
const config = require('../../../core/shared/config');
const labs = require('../../../core/shared/labs');
const Papa = require('papaparse');
const {mockManager} = require('../../utils/e2e-framework');
describe('Members API', function () {
let request;
beforeEach(function () {
sinon.stub(labs, 'isSet').withArgs('multipleProducts').returns(false);
mockManager.mockLabsDisabled('multipleProducts');
});
afterEach(function () {
sinon.restore();
mockManager.restore();
});
before(async function () {

View File

@ -1,8 +1,6 @@
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 () {
let agent;
@ -14,13 +12,13 @@ describe('Tiers API', function () {
});
beforeEach(function () {
sinon.stub(labs, 'isSet').withArgs('multipleProducts').returns(false);
mockManager.mockLabsDisabled('multipleProducts');
const stripeService = require('../../../core/server/services/stripe');
stripeService.api._configured = true;
});
afterEach(function () {
sinon.restore();
mockManager.restore();
const stripeService = require('../../../core/server/services/stripe');
stripeService.api._configured = false;
});

View File

@ -28,7 +28,26 @@ const mockLabsEnabled = (flag, alpha = 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) => {
@ -74,6 +93,7 @@ const restore = () => {
module.exports = {
mockMail,
mockLabsEnabled,
mockLabsDisabled,
restore,
assert: {
sentEmailCount,

View File

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