diff --git a/test/utils/admin-api-test-agent.js b/test/utils/admin-api-test-agent.js index c290a94494..d8b26b0252 100644 --- a/test/utils/admin-api-test-agent.js +++ b/test/utils/admin-api-test-agent.js @@ -1,4 +1,4 @@ -const Agent = require('@tryghost/express-test'); +const TestAgent = require('./test-agent'); const errors = require('@tryghost/errors'); const DataGenerator = require('./fixtures/data-generator'); @@ -14,15 +14,9 @@ const ownerUser = { * @param {String} options.apiURL * @param {String} options.originURL */ -class AdminAPITestAgent extends Agent { +class AdminAPITestAgent extends TestAgent { constructor(app, options) { - super(app, { - baseUrl: options.apiURL, - headers: { - host: options.originURL.replace(/http:\/\//, ''), - origin: options.originURL - } - }); + super(app, options); } async loginAs(email, password) { diff --git a/test/utils/members-api-test-agent.js b/test/utils/members-api-test-agent.js index 336820c6c8..c76def0ba5 100644 --- a/test/utils/members-api-test-agent.js +++ b/test/utils/members-api-test-agent.js @@ -1,21 +1,18 @@ -const Agent = require('@tryghost/express-test'); +const TestAgent = require('./test-agent'); /** + * NOTE: this class is not doing much at the moment. It's rather a placeholder to put + * any Members API specific functionality into. 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 MembersAPITestAgent extends Agent { +class MembersAPITestAgent extends TestAgent { constructor(app, options) { - super(app, { - baseUrl: options.apiURL, - headers: { - host: options.originURL.replace(/http:\/\//, ''), - origin: options.originURL - } - }); + super(app, options); } } diff --git a/test/utils/test-agent.js b/test/utils/test-agent.js new file mode 100644 index 0000000000..d7a62a91b6 --- /dev/null +++ b/test/utils/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 TestAgent extends Agent { + constructor(app, options) { + super(app, { + baseUrl: options.apiURL, + headers: { + host: options.originURL.replace(/http:\/\//, ''), + origin: options.originURL + } + }); + } +} + +module.exports = TestAgent;