From 5fe80c82c5380e75795a4ef59e151adbc22cd7da Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 1 Nov 2022 17:26:08 +0800 Subject: [PATCH] Exposed Content API agent in e2e test utils refs https://github.com/TryGhost/Toolbox/issues/461 - When testing OPTIONS requests there is a need to get all possible agents available in the system. The "getAgentsWithFrontend" serves exactly this purpose - create all possible agents while starting Ghost instance only once - This is groundwork for OPTIONS request caching tests and improvements --- ghost/core/test/utils/e2e-framework.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ghost/core/test/utils/e2e-framework.js b/ghost/core/test/utils/e2e-framework.js index baf55ce059..327cb239f5 100644 --- a/ghost/core/test/utils/e2e-framework.js +++ b/ghost/core/test/utils/e2e-framework.js @@ -292,13 +292,15 @@ const getAgentsForMembers = async () => { }; /** - * TODO: for now this agent returns a supertest agent instead of a proper test agent. - * We need to add support for this. + * @NOTE: for now method returns a supertest agent for Frontend instead of test agent with snapshot support. + * frontendAgent should be returning an instance of TestAgent. + * @returns {Promise<{adminAgent: InstanceType, membersAgent: InstanceType, frontendAgent: InstanceType, contentAPIAgent: InstanceType}>} agents */ const getAgentsWithFrontend = async () => { let membersAgent; let adminAgent; let frontendAgent; + let contentAPIAgent; const bootOptions = { frontend: true, @@ -316,6 +318,10 @@ const getAgentsWithFrontend = async () => { apiURL: '/ghost/api/admin/', originURL }); + contentAPIAgent = new ContentAPITestAgent(app, { + apiURL: '/ghost/api/content/', + originURL + }); frontendAgent = supertest.agent(originURL); } catch (error) { error.message = `Unable to create test agent. ${error.message}`; @@ -325,7 +331,8 @@ const getAgentsWithFrontend = async () => { return { adminAgent, membersAgent, - frontendAgent + frontendAgent, + contentAPIAgent }; };