0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

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.
This commit is contained in:
Fabien "egg" O'Carroll 2022-02-11 15:11:37 +02:00 committed by Fabien 'egg' O'Carroll
parent e30498ca2c
commit af66ab02c8

View file

@ -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<TestAgent>} 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