mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
Extracted separate member agent test util
refs https://github.com/TryGhost/Toolbox/issues/214 - TestAgent was used to initialize both Admin & Member API agents, which is somewhat confusing because Member API does not have the same "loginAs" functionality like Admin API does - Having distinct agents for each API makes the class API cleaner with possibility to extract common functionality even further
This commit is contained in:
parent
9c5c41b927
commit
4b5852fab1
@ -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;
|
@ -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
|
||||
});
|
||||
|
22
test/utils/members-api-test-agent.js
Normal file
22
test/utils/members-api-test-agent.js
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user