0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00
ghost/test/utils/members-api-test-agent.js
Kevin Ansfield 25c0b75426 Added comments API tests
refs https://github.com/TryGhost/Team/issues/1664

Note: we put it in the members-comments folder because some issue with test ordering
- refs https://ghost.slack.com/archives/C02G9E68C/p1657538586658649?thread_ts=1657522575.865029&cid=C02G9E68C
- There is something wrong with the url service reset when running multiple tests
- Currently we are doing a soft reset, this needs investigating
- Changing the order so that the comments API tests are executed after the content API tests, fixes the issue too.

Co-authored-by: Simon Backx <simon@ghost.org>
2022-07-12 10:24:02 +02:00

37 lines
1.2 KiB
JavaScript

const TestAgent = require('./test-agent');
const errors = require('@tryghost/errors');
/**
* 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 TestAgent {
constructor(app, options) {
super(app, options);
}
async loginAs(email) {
const membersService = require('../../core/server/services/members');
const magicLink = await membersService.api.getMagicLink(email);
const magicLinkUrl = new URL(magicLink);
const token = magicLinkUrl.searchParams.get('token');
const res = await this.get(`/?token=${token}`);
if (res.statusCode !== 302) {
throw new errors.IncorrectUsageError({
message: res.body.errors[0].message
});
}
return res.headers['set-cookie'];
}
}
module.exports = MembersAPITestAgent;