diff --git a/test/utils/e2e-framework.js b/test/utils/e2e-framework.js index b3aabbc15e..51c2853f04 100644 --- a/test/utils/e2e-framework.js +++ b/test/utils/e2e-framework.js @@ -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} 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 diff --git a/test/utils/ghost-api-test-agent.js b/test/utils/ghost-api-test-agent.js new file mode 100644 index 0000000000..b279135ec5 --- /dev/null +++ b/test/utils/ghost-api-test-agent.js @@ -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;