diff --git a/test/utils/test-agent.js b/test/utils/admin-api-test-agent.js similarity index 95% rename from test/utils/test-agent.js rename to test/utils/admin-api-test-agent.js index 6d1ec0d4b8..c290a94494 100644 --- a/test/utils/test-agent.js +++ b/test/utils/admin-api-test-agent.js @@ -14,7 +14,7 @@ const ownerUser = { * @param {String} options.apiURL * @param {String} options.originURL */ -class TestAgent extends Agent { +class AdminAPITestAgent extends Agent { constructor(app, options) { super(app, { baseUrl: options.apiURL, @@ -53,4 +53,4 @@ class TestAgent extends Agent { } } -module.exports = TestAgent; +module.exports = AdminAPITestAgent; diff --git a/test/utils/e2e-framework.js b/test/utils/e2e-framework.js index 5562499aaf..a5e98a87a7 100644 --- a/test/utils/e2e-framework.js +++ b/test/utils/e2e-framework.js @@ -27,7 +27,8 @@ const urlServiceUtils = require('./url-service-utils'); const mockManager = require('./e2e-framework-mock-manager'); const boot = require('../../core/boot'); -const TestAgent = require('./test-agent'); +const AdminAPITestAgent = require('./admin-api-test-agent'); +const MembersAPITestAgent = require('./members-api-test-agent'); const db = require('./db-utils'); // Services that need resetting @@ -161,7 +162,7 @@ const getAdminAPIAgent = async (options = {}) => { const app = await startGhost(bootOptions); const originURL = configUtils.config.get('url'); - return new TestAgent(app, { + return new AdminAPITestAgent(app, { apiURL: '/ghost/api/canary/admin/', originURL }); @@ -186,7 +187,7 @@ const getMembersAPIAgent = async () => { const app = await startGhost(bootOptions); const originURL = configUtils.config.get('url'); - return new TestAgent(app, { + return new MembersAPITestAgent(app, { apiURL: '/members/', originURL }); @@ -198,7 +199,7 @@ const getMembersAPIAgent = async () => { /** * - * @returns {Promise<{adminAgent: TestAgent, membersAgent: TestAgent}>} agent + * @returns {Promise<{adminAgent: AdminAPITestAgent, membersAgent: MembersAPITestAgent}>} agents */ const getAgentsForMembers = async () => { let membersAgent; @@ -212,11 +213,11 @@ const getAgentsForMembers = async () => { const app = await startGhost(bootOptions); const originURL = configUtils.config.get('url'); - membersAgent = new TestAgent(app, { + membersAgent = new MembersAPITestAgent(app, { apiURL: '/members/', originURL }); - adminAgent = new TestAgent(app, { + adminAgent = new AdminAPITestAgent(app, { apiURL: '/ghost/api/canary/admin/', originURL }); diff --git a/test/utils/members-api-test-agent.js b/test/utils/members-api-test-agent.js new file mode 100644 index 0000000000..336820c6c8 --- /dev/null +++ b/test/utils/members-api-test-agent.js @@ -0,0 +1,22 @@ +const Agent = require('@tryghost/express-test'); + +/** + * @constructor + * @param {Object} app Ghost express app instance + * @param {Object} options + * @param {String} options.apiURL + * @param {String} options.originURL + */ +class MembersAPITestAgent extends Agent { + constructor(app, options) { + super(app, { + baseUrl: options.apiURL, + headers: { + host: options.originURL.replace(/http:\/\//, ''), + origin: options.originURL + } + }); + } +} + +module.exports = MembersAPITestAgent;