mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-11 18:35:22 +03: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:
parent
a1edff4b0c
commit
83aa35241a
@ -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 () {
|
||||
|
@ -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;
|
||||
});
|
||||
|
@ -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,
|
||||
|
@ -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}`;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user