mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added root Ghost server/API test agent
refs https://github.com/TryGhost/Team/issues/1640 - Some tests require making request to the root of the mounted server path like `GET /ghost/.well-known/jwks.json`. These are not stricly APIs like Admin, Content, and Members. They do need a separate agent to distinguish the configuration - for this agetn we can stop loading some parts like "server" in the future to speed things up (didn't work straight out of the box)
This commit is contained in:
parent
5975740d69
commit
a18469a3be
2 changed files with 48 additions and 1 deletions
|
@ -30,6 +30,7 @@ const boot = require('../../core/boot');
|
|||
const AdminAPITestAgent = require('./admin-api-test-agent');
|
||||
const MembersAPITestAgent = require('./members-api-test-agent');
|
||||
const ContentAPITestAgent = require('./content-api-test-agent');
|
||||
const GhostAPITestAgent = require('./ghost-api-test-agent');
|
||||
const db = require('./db-utils');
|
||||
|
||||
// Services that need resetting
|
||||
|
@ -219,6 +220,32 @@ const getMembersAPIAgent = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a GhostAPITestAgent, which is a drop-in substitution for supertest
|
||||
* It is automatically hooked up to the Ghost API so you can make requests to e.g.
|
||||
* agent.get('/well-known/jwks.json') without having to worry about URL paths
|
||||
*
|
||||
* @returns {Promise<GhostAPITestAgent>} agent
|
||||
*/
|
||||
const getGhostAPIAgent = async () => {
|
||||
const bootOptions = {
|
||||
frontend: false
|
||||
};
|
||||
|
||||
try {
|
||||
const app = await startGhost(bootOptions);
|
||||
const originURL = configUtils.config.get('url');
|
||||
|
||||
return new GhostAPITestAgent(app, {
|
||||
apiURL: '/ghost/',
|
||||
originURL
|
||||
});
|
||||
} catch (error) {
|
||||
error.message = `Unable to create test agent. ${error.message}`;
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {Promise<{adminAgent: AdminAPITestAgent, membersAgent: MembersAPITestAgent}>} agents
|
||||
|
@ -260,7 +287,8 @@ module.exports = {
|
|||
getAdminAPIAgent,
|
||||
getMembersAPIAgent,
|
||||
getContentAPIAgent,
|
||||
getAgentsForMembers
|
||||
getAgentsForMembers,
|
||||
getGhostAPIAgent
|
||||
},
|
||||
|
||||
// Mocks and Stubs
|
||||
|
|
19
test/utils/ghost-api-test-agent.js
Normal file
19
test/utils/ghost-api-test-agent.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const TestAgent = require('./test-agent');
|
||||
|
||||
/**
|
||||
* NOTE: this class is not doing much at the moment. It's rather a placeholder to test
|
||||
* any Ghost API specific functionality, like /.well-known. If there is none in the nearest
|
||||
* future, it would make sense to remove it alltogether.
|
||||
* @constructor
|
||||
* @param {Object} app Ghost express app instance
|
||||
* @param {Object} options
|
||||
* @param {String} options.apiURL
|
||||
* @param {String} options.originURL
|
||||
*/
|
||||
class GhostAPITestAgent extends TestAgent {
|
||||
constructor(app, options) {
|
||||
super(app, options);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GhostAPITestAgent;
|
Loading…
Add table
Reference in a new issue