From af66ab02c8de6d942fe8b1bd26f1eb51bdfe3540 Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Fri, 11 Feb 2022 15:11:37 +0200 Subject: [PATCH] Added getMembersAPIAgent to e2e-framework no-issue The Members API is served on a different endpoint to the Admin API, and also requires that the frontend is booted. This agent is to be used when testing the Members API, e.g. Stripe webhooks or Members config. --- test/utils/e2e-framework.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/utils/e2e-framework.js b/test/utils/e2e-framework.js index 9337d3c482..3baffd41da 100644 --- a/test/utils/e2e-framework.js +++ b/test/utils/e2e-framework.js @@ -149,10 +149,36 @@ const getAdminAPIAgent = async (options = {}) => { } }; +/** + * Creates a TestAgent which is a drop-in substitution for supertest + * It is automatically hooked up to the Members API so you can make requests to e.g. + * agent.get('/webhooks/stripe/') without having to worry about URL paths + * + * @returns {Promise} agent + */ +const getMembersAPIAgent = async () => { + const bootOptions = { + frontend: true + }; + try { + const app = await startGhost(bootOptions); + const originURL = configUtils.config.get('url'); + + return new TestAgent(app, { + apiURL: '/members/', + originURL + }); + } catch (error) { + error.message = `Unable to create test agent. ${error.message}`; + throw error; + } +}; + module.exports = { // request agent agentProvider: { - getAdminAPIAgent + getAdminAPIAgent, + getMembersAPIAgent }, // Mocks and Stubs