mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Refactored request initialization with supertest
refs https://github.com/TryGhost/Toolbox/issues/152 refs5bea089dfe
refs16ad5f73c4
- The refactor is heavily inspired by the referenced commit from @ErisDS - This refactor is meant to serve as a template for further refactors and unification of the abstraction over "request". Should allow us to be more agnostic towards the library that's powering the request thing. For example, mock-express style of request handling could substitute or get substututed easily if all tests are behind similar "get(Authenticated)Agent" interface
This commit is contained in:
parent
b7231875a0
commit
05a4fbfd2a
3 changed files with 19 additions and 18 deletions
|
@ -14,8 +14,7 @@ let request;
|
|||
describe('Authentication API canary', function () {
|
||||
describe('Blog setup', function () {
|
||||
before(async function () {
|
||||
const app = await localUtils.startGhost({forceStart: true});
|
||||
request = supertest.agent(app);
|
||||
request = await localUtils.getAgent({forceStart: true});
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
@ -133,10 +132,7 @@ describe('Authentication API canary', function () {
|
|||
|
||||
describe('Invitation', function () {
|
||||
before(async function () {
|
||||
const app = await localUtils.startGhost();
|
||||
request = supertest.agent(app);
|
||||
|
||||
await localUtils.doAuth(request, 'invites');
|
||||
request = await localUtils.getAuthenticatedRequestAgent(null, 'invites');
|
||||
});
|
||||
|
||||
it('check invite with invalid email', function () {
|
||||
|
@ -225,10 +221,7 @@ describe('Authentication API canary', function () {
|
|||
const user = testUtils.DataGenerator.forModel.users[0];
|
||||
|
||||
before(async function () {
|
||||
const app = await localUtils.startGhost({forceStart: true});
|
||||
request = supertest.agent(app);
|
||||
|
||||
await localUtils.doAuth(request);
|
||||
request = await localUtils.getAuthenticatedRequestAgent({forceStart: true});
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
@ -388,10 +381,7 @@ describe('Authentication API canary', function () {
|
|||
describe('Reset all passwords', function () {
|
||||
let sendEmail;
|
||||
before(async function () {
|
||||
const app = await localUtils.startGhost({forceStart: true});
|
||||
request = supertest.agent(app);
|
||||
|
||||
await localUtils.doAuth(request);
|
||||
request = await localUtils.getAuthenticatedRequestAgent({forceStart: true});
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const should = require('should');
|
||||
const supertest = require('supertest');
|
||||
const testUtils = require('../../../../utils');
|
||||
const localUtils = require('./utils');
|
||||
const config = require('../../../../../core/shared/config');
|
||||
|
@ -8,9 +7,7 @@ describe('Config API', function () {
|
|||
let request;
|
||||
|
||||
before(async function () {
|
||||
const app = await localUtils.startGhost();
|
||||
request = supertest.agent(app);
|
||||
await localUtils.doAuth(request);
|
||||
request = await localUtils.getAuthenticatedRequestAgent();
|
||||
});
|
||||
|
||||
it('can retrieve config and all expected properties', async function () {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const url = require('url');
|
||||
const _ = require('lodash');
|
||||
const supertest = require('supertest');
|
||||
const testUtils = require('../../../../utils');
|
||||
|
||||
const API_URL = '/ghost/api/canary/admin/';
|
||||
|
@ -213,6 +214,19 @@ module.exports = {
|
|||
return await testUtils.startGhost(Object.assign(defaults, overrides));
|
||||
},
|
||||
|
||||
async getAgent(options) {
|
||||
const app = await this.startGhost(options);
|
||||
|
||||
return supertest.agent(app);
|
||||
},
|
||||
|
||||
async getAuthenticatedAgent(bootOptions, fixtureOptions) {
|
||||
const request = await this.getAgent(bootOptions);
|
||||
await this.doAuth(request, fixtureOptions);
|
||||
|
||||
return request;
|
||||
},
|
||||
|
||||
getValidAdminToken(endpoint, key) {
|
||||
const jwt = require('jsonwebtoken');
|
||||
key = key || testUtils.DataGenerator.Content.api_keys[0];
|
||||
|
|
Loading…
Add table
Reference in a new issue