0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

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
This commit is contained in:
Naz 2022-11-01 17:26:08 +08:00 committed by naz
parent ab678c3a90
commit 5fe80c82c5

View file

@ -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<AdminAPITestAgent>, membersAgent: InstanceType<MembersAPITestAgent>, frontendAgent: InstanceType<supertest.SuperAgentTest>, contentAPIAgent: InstanceType<ContentAPITestAgent>}>} 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
};
};