mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
Extracted TestAgent class for test utils
refs https://github.com/TryGhost/Toolbox/issues/214 - The constructor logic was duplicated across test agents, so made sence to extract the logic into a common class
This commit is contained in:
parent
4b5852fab1
commit
178e7db066
@ -1,4 +1,4 @@
|
|||||||
const Agent = require('@tryghost/express-test');
|
const TestAgent = require('./test-agent');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const DataGenerator = require('./fixtures/data-generator');
|
const DataGenerator = require('./fixtures/data-generator');
|
||||||
|
|
||||||
@ -14,15 +14,9 @@ const ownerUser = {
|
|||||||
* @param {String} options.apiURL
|
* @param {String} options.apiURL
|
||||||
* @param {String} options.originURL
|
* @param {String} options.originURL
|
||||||
*/
|
*/
|
||||||
class AdminAPITestAgent extends Agent {
|
class AdminAPITestAgent extends TestAgent {
|
||||||
constructor(app, options) {
|
constructor(app, options) {
|
||||||
super(app, {
|
super(app, options);
|
||||||
baseUrl: options.apiURL,
|
|
||||||
headers: {
|
|
||||||
host: options.originURL.replace(/http:\/\//, ''),
|
|
||||||
origin: options.originURL
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async loginAs(email, password) {
|
async loginAs(email, password) {
|
||||||
|
@ -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
|
* @constructor
|
||||||
* @param {Object} app Ghost express app instance
|
* @param {Object} app Ghost express app instance
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @param {String} options.apiURL
|
* @param {String} options.apiURL
|
||||||
* @param {String} options.originURL
|
* @param {String} options.originURL
|
||||||
*/
|
*/
|
||||||
class MembersAPITestAgent extends Agent {
|
class MembersAPITestAgent extends TestAgent {
|
||||||
constructor(app, options) {
|
constructor(app, options) {
|
||||||
super(app, {
|
super(app, options);
|
||||||
baseUrl: options.apiURL,
|
|
||||||
headers: {
|
|
||||||
host: options.originURL.replace(/http:\/\//, ''),
|
|
||||||
origin: options.originURL
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
test/utils/test-agent.js
Normal file
22
test/utils/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 TestAgent extends Agent {
|
||||||
|
constructor(app, options) {
|
||||||
|
super(app, {
|
||||||
|
baseUrl: options.apiURL,
|
||||||
|
headers: {
|
||||||
|
host: options.originURL.replace(/http:\/\//, ''),
|
||||||
|
origin: options.originURL
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TestAgent;
|
Loading…
Reference in New Issue
Block a user