mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
fa373e0956
refs https://github.com/TryGhost/Toolbox/issues/215 - The ContentAPI needs it's own test agent, so we can write e2e tests. - The main method mostly to be used by the test suites is "authenticate" - it add necessary authentication keys to the request. The agent is not authenticated by default because there are suites that need to test the "non authenticated" requests. Also, there's a need to have the default API key inserted from fixtures level before authenticating (it's not strictly necessary because the key is not dynamic, but I think coupling this point would be a bad move)
34 lines
818 B
JavaScript
34 lines
818 B
JavaScript
const TestAgent = require('./test-agent');
|
|
const DataGenerator = require('./fixtures/data-generator');
|
|
|
|
const defaultContentAPISecretKey = DataGenerator.Content.api_keys[1].secret;
|
|
|
|
/**
|
|
* @constructor
|
|
* @param {Object} app Ghost express app instance
|
|
* @param {Object} options
|
|
* @param {String} options.apiURL
|
|
* @param {String} options.originURL
|
|
*/
|
|
class ContentAPITestAgent extends TestAgent {
|
|
constructor(app, options) {
|
|
super(app, options);
|
|
}
|
|
|
|
async authenticateWithSecret(secret) {
|
|
this.defaults.queryParams = {
|
|
key: secret
|
|
};
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @description Authenticate with default content api keys
|
|
*/
|
|
authenticate() {
|
|
return this.authenticateWithSecret(defaultContentAPISecretKey);
|
|
}
|
|
}
|
|
|
|
module.exports = ContentAPITestAgent;
|