Improved webhooks e2e test bootstrap speed

refs https://github.com/TryGhost/Toolbox/issues/214

- Calling `getMembersAPIAgent` and `getAdminAPIAgent` separately was booting Ghost twice, which caused a significant performance degradation.
- Additionally, having two calls was slightly ugly and having once utility function that delivers multiple agents at once feels like  more readable syntax
This commit is contained in:
Naz 2022-02-17 15:31:48 +07:00
parent 9b4d61ef2e
commit 884f837bd7
2 changed files with 42 additions and 3 deletions

View File

@ -14,8 +14,11 @@ describe('Members API', function () {
// And it's initialised at boot - so mocking it before
// Probably wanna replace this with a settinfs fixture mock or smth??
mockManager.setupStripe();
membersAgent = await agentProvider.getMembersAPIAgent();
adminAgent = await agentProvider.getAdminAPIAgent();
const agents = await agentProvider.getAgentsForMembers();
membersAgent = agents.membersAgent;
adminAgent = agents.adminAgent;
await fixtureManager.init('members');
await adminAgent.loginAsOwner();
});

View File

@ -196,11 +196,47 @@ const getMembersAPIAgent = async () => {
}
};
/**
*
* @returns {Promise<{adminAgent: TestAgent, membersAgent: TestAgent}>} agent
*/
const getAgentsForMembers = async () => {
let membersAgent;
let adminAgent;
const bootOptions = {
frontend: true
};
try {
const app = await startGhost(bootOptions);
const originURL = configUtils.config.get('url');
membersAgent = new TestAgent(app, {
apiURL: '/members/',
originURL
});
adminAgent = new TestAgent(app, {
apiURL: '/ghost/api/canary/admin/',
originURL
});
} catch (error) {
error.message = `Unable to create test agent. ${error.message}`;
throw error;
}
return {
adminAgent,
membersAgent
};
};
module.exports = {
// request agent
agentProvider: {
getAdminAPIAgent,
getMembersAPIAgent
getMembersAPIAgent,
getAgentsForMembers
},
// Mocks and Stubs