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

Add option to include member in the adminAPIAgent

- The admin API test agent doesn't boot the Ghost frontend, which is where members routes are currently located
- This means we can't test members properly as we don't have access to webhooks etc
- This change adds a members option to getAdminAPIAgent(), which in turn enables the frontend
- We do it this way so that we can easily change the implementation later, e.g. if we have the option to boot members directly
This commit is contained in:
Hannah Wolfe 2022-02-11 12:32:08 +00:00
parent 9375a1701a
commit 00e4a8cad4
No known key found for this signature in database
GPG key ID: AB586C3B5AE5C037

View file

@ -29,7 +29,14 @@ const boot = require('../../core/boot');
const TestAgent = require('./test-agent');
const db = require('./db-utils');
const startGhost = async () => {
/**
* @param {Object} [options={}]
* @param {Boolean} [options.backend] Boot the backend
* @param {Boolean} [options.frontend] Boot the frontend
* @param {Boolean} [options.server] Start a server
* @returns {Express.Application} ghost
*/
const startGhost = async (options = {}) => {
/**
* We never use the root content folder for testing!
* We use a tmp folder.
@ -49,7 +56,7 @@ const startGhost = async () => {
// Ensure the DB state
await resetDb();
return boot(defaults);
return boot(Object.assign({}, defaults, options));
};
/**
@ -113,15 +120,23 @@ const resetDb = async () => {
};
/**
* Creates a TestAgent which is a drop-in substitution for supertest
* Creates a TestAgent which is a drop-in substitution for supertest.
* It is automatically hooked up to the Admin API so you can make requests to e.g.
* agent.get('/posts/') without having to worry about URL paths
*
* @param {Object} [options={}]
* @param {Boolean} [options.membersApp] Include members in the boot process
* @returns {TestAgent} agent
*/
const getAdminAPIAgent = async () => {
const getAdminAPIAgent = async (options = {}) => {
const bootOptions = {};
if (options.members) {
bootOptions.frontend = true;
}
try {
const app = await startGhost();
const app = await startGhost(bootOptions);
const originURL = configUtils.config.get('url');
return new TestAgent(app, {