From d7c2759b3f705c44130d6d4a14f0fdba4fc368b1 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 8 Feb 2022 14:39:24 +0000 Subject: [PATCH] Improved agentProvider api in e2e-framework refs: https://github.com/TryGhost/Toolbox/issues/158 - Working up to having these be the defacto "reference" tests - Changing this allows for the fact that there will be a getContentAPIAgent, and probably more in future - Abstracting away the path to a single location will make updating API paths easier later too --- test/regression/api/admin/authentication.test.js | 8 ++++---- test/regression/api/admin/members.test.js | 2 +- test/regression/api/admin/site.test.js | 2 +- test/utils/e2e-framework.js | 14 ++++++++------ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/test/regression/api/admin/authentication.test.js b/test/regression/api/admin/authentication.test.js index 1ee5893bcf..0732b34a4e 100644 --- a/test/regression/api/admin/authentication.test.js +++ b/test/regression/api/admin/authentication.test.js @@ -15,7 +15,7 @@ describe('Authentication API', function () { describe('Blog setup', function () { before(async function () { - agent = await agentProvider.getAgent('/ghost/api/canary/admin/'); + agent = await agentProvider.getAdminAPIAgent(); }); beforeEach(function () { @@ -134,7 +134,7 @@ describe('Authentication API', function () { describe('Invitation', function () { before(async function () { - agent = await agentProvider.getAgent('/ghost/api/canary/admin/'); + agent = await agentProvider.getAdminAPIAgent(); // NOTE: this order of fixture initialization boggles me. Ideally should not depend on agent/login sequence await fixtureManager.init('invites'); await agent.loginAsOwner(); @@ -231,7 +231,7 @@ describe('Authentication API', function () { const user = testUtils.DataGenerator.forModel.users[0]; before(async function () { - agent = await agentProvider.getAgent('/ghost/api/canary/admin/'); + agent = await agentProvider.getAdminAPIAgent(); // NOTE: this order of fixture initialization boggles me. Ideally should not depend on agent/login sequence await fixtureManager.init('invites'); await agent.loginAsOwner(); @@ -373,7 +373,7 @@ describe('Authentication API', function () { describe('Reset all passwords', function () { before(async function () { - agent = await agentProvider.getAgent('/ghost/api/canary/admin/'); + agent = await agentProvider.getAdminAPIAgent(); // NOTE: this order of fixture initialization boggles me. Ideally should not depend on agent/login sequence await fixtureManager.init('invites'); await agent.loginAsOwner(); diff --git a/test/regression/api/admin/members.test.js b/test/regression/api/admin/members.test.js index 956cbc7eb7..9cdad7c7ee 100644 --- a/test/regression/api/admin/members.test.js +++ b/test/regression/api/admin/members.test.js @@ -15,7 +15,7 @@ describe('Members API', function () { }); before(async function () { - agent = await agentProvider.getAgent('/ghost/api/canary/admin/'); + agent = await agentProvider.getAdminAPIAgent(); await fixtureManager.init('members'); await agent.loginAsOwner(); }); diff --git a/test/regression/api/admin/site.test.js b/test/regression/api/admin/site.test.js index c134ba3a63..54d86d094c 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.getAgent('/ghost/api/canary/admin/'); + agent = await agentProvider.getAdminAPIAgent('/ghost/api/canary/admin/'); }); it('can retrieve config and all expected properties', async function () { diff --git a/test/utils/e2e-framework.js b/test/utils/e2e-framework.js index 73038f8333..674b2d7a6f 100644 --- a/test/utils/e2e-framework.js +++ b/test/utils/e2e-framework.js @@ -113,17 +113,19 @@ const resetDb = async () => { }; /** - * Creates a TestAgent which is a drop-in substitution for supertest hooked into Ghost. - * @param {String} apiURL - * @returns {TestAgent} + * Creates a TestAgent which is a drop-in substitution for supertest + * It is automatically hooked up to the Admin API so you can make requests to e.g. + * agent.get('/posts/') without having to worry about URL paths + * + * @returns {TestAgent} agent */ -const getAgent = async (apiURL) => { +const getAdminAPIAgent = async () => { try { const app = await startGhost(); const originURL = configUtils.config.get('url'); return new TestAgent(app, { - apiURL, + apiURL: '/ghost/api/canary/admin/', originURL }); } catch (error) { @@ -134,7 +136,7 @@ const getAgent = async (apiURL) => { module.exports = { // request agent agentProvider: { - getAgent + getAdminAPIAgent }, // Mocks and Stubs