From c80e68b93a5a4de6ce215ba5797d3aee967ddb0c Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Thu, 10 Feb 2022 12:17:21 +0000 Subject: [PATCH] Updated all members tests to use mockManager - This part of the framework can be used in isolation - Using mockManager everywhere makes it more visible how to use it - Aside: fixed .getAdminAPIAgent not needing a URL in site tests whilst cleaning up --- .../api/admin/members-importer.test.js | 18 +++++------------- .../api/admin/members_signin_url.test.js | 13 ++++++------- test/regression/api/admin/site.test.js | 2 +- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/test/regression/api/admin/members-importer.test.js b/test/regression/api/admin/members-importer.test.js index 793e8ac340..571c5d29ff 100644 --- a/test/regression/api/admin/members-importer.test.js +++ b/test/regression/api/admin/members-importer.test.js @@ -2,24 +2,15 @@ const path = require('path'); const querystring = require('querystring'); const should = require('should'); const supertest = require('supertest'); -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 mailService = require('../../../../core/server/services/mail'); + +const {mockManager} = require('../../../utils/e2e-framework'); let request; describe('Members Importer API', function () { - before(function () { - sinon.stub(labs, 'isSet').withArgs('members').returns(true); - }); - - after(function () { - sinon.restore(); - }); - before(async function () { await localUtils.startGhost(); request = supertest.agent(config.get('url')); @@ -27,11 +18,12 @@ describe('Members Importer API', function () { }); beforeEach(function () { - sinon.stub(mailService.GhostMailer.prototype, 'send').resolves('Mail is disabled'); + mockManager.mockMail(); + mockManager.mockLabsEnabled('members'); }); afterEach(function () { - sinon.restore(); + mockManager.restore(); }); it('Can import CSV with minimum one field and labels', function () { diff --git a/test/regression/api/admin/members_signin_url.test.js b/test/regression/api/admin/members_signin_url.test.js index b8a1bfac3c..a0f89d344c 100644 --- a/test/regression/api/admin/members_signin_url.test.js +++ b/test/regression/api/admin/members_signin_url.test.js @@ -1,21 +1,20 @@ -const path = require('path'); const should = require('should'); const supertest = require('supertest'); -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 {mockManager} = require('../../../utils/e2e-framework'); let request; describe('Members Sigin URL API', function () { - before(function () { - sinon.stub(labs, 'isSet').withArgs('members').returns(true); + beforeEach(function () { + mockManager.mockLabsEnabled('members'); }); - after(function () { - sinon.restore(); + afterEach(function () { + mockManager.restore(); }); describe('As Owner', function () { diff --git a/test/regression/api/admin/site.test.js b/test/regression/api/admin/site.test.js index ab7c060082..fa04ed360e 100644 --- a/test/regression/api/admin/site.test.js +++ b/test/regression/api/admin/site.test.js @@ -5,7 +5,7 @@ describe('Site API', function () { let agent; before(async function () { - agent = await agentProvider.getAdminAPIAgent('/ghost/api/canary/admin/'); + agent = await agentProvider.getAdminAPIAgent(); }); it('can retrieve config and all expected properties', async function () {