Renamed request to agent in tests

- I _think_ this makes it easier to read and understand what's happening
This commit is contained in:
Hannah Wolfe 2022-02-04 15:32:29 +00:00
parent 895acc9ed0
commit 0bf9d6f642
No known key found for this signature in database
GPG Key ID: AB586C3B5AE5C037
2 changed files with 29 additions and 29 deletions

View File

@ -8,12 +8,12 @@ const models = require('../../../../../core/server/models/index');
const settingsCache = require('../../../../../core/shared/settings-cache'); const settingsCache = require('../../../../../core/shared/settings-cache');
describe('Authentication API canary', function () { describe('Authentication API canary', function () {
let request; let agent;
let emailStub; let emailStub;
describe('Blog setup', function () { describe('Blog setup', function () {
before(async function () { before(async function () {
request = await framework.getAgent('/ghost/api/canary/admin/'); agent = await framework.getAgent('/ghost/api/canary/admin/');
}); });
after(async function () { after(async function () {
@ -29,7 +29,7 @@ describe('Authentication API canary', function () {
}); });
it('is setup? no', async function () { it('is setup? no', async function () {
const res = await request const res = await agent
.get('authentication/setup') .get('authentication/setup')
.expect(200); .expect(200);
@ -41,7 +41,7 @@ describe('Authentication API canary', function () {
}); });
it('complete setup', async function () { it('complete setup', async function () {
const res = await request const res = await agent
.post('authentication/setup') .post('authentication/setup')
.send({ .send({
setup: [{ setup: [{
@ -69,7 +69,7 @@ describe('Authentication API canary', function () {
}); });
it('is setup? yes', async function () { it('is setup? yes', async function () {
const res = await request const res = await agent
.get('authentication/setup'); .get('authentication/setup');
expect(res.body).to.matchSnapshot(); expect(res.body).to.matchSnapshot();
@ -80,7 +80,7 @@ describe('Authentication API canary', function () {
}); });
it('complete setup again', function () { it('complete setup again', function () {
return request return agent
.post('authentication/setup') .post('authentication/setup')
.send({ .send({
setup: [{ setup: [{
@ -96,9 +96,9 @@ describe('Authentication API canary', function () {
it('update setup', async function () { it('update setup', async function () {
await framework.initFixtures(); await framework.initFixtures();
await request.loginAsOwner(); await agent.loginAsOwner();
const res = await request const res = await agent
.put('authentication/setup') .put('authentication/setup')
.send({ .send({
setup: [{ setup: [{
@ -127,10 +127,10 @@ describe('Authentication API canary', function () {
describe('Invitation', function () { describe('Invitation', function () {
before(async function () { before(async function () {
request = await framework.getAgent('/ghost/api/canary/admin/'); agent = await framework.getAgent('/ghost/api/canary/admin/');
// NOTE: this order of fixture initialization boggles me. Ideally should not depend on agent/login sequence // NOTE: this order of fixture initialization boggles me. Ideally should not depend on agent/login sequence
await framework.initFixtures('invites'); await framework.initFixtures('invites');
await request.loginAsOwner(); await agent.loginAsOwner();
}); });
after(async function () { after(async function () {
@ -138,14 +138,14 @@ describe('Authentication API canary', function () {
}); });
it('check invite with invalid email', function () { it('check invite with invalid email', function () {
return request return agent
.get('authentication/invitation?email=invalidemail') .get('authentication/invitation?email=invalidemail')
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(400); .expect(400);
}); });
it('check valid invite', async function () { it('check valid invite', async function () {
const res = await request const res = await agent
.get(`authentication/invitation?email=${testUtils.DataGenerator.forKnex.invites[0].email}`) .get(`authentication/invitation?email=${testUtils.DataGenerator.forKnex.invites[0].email}`)
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200); .expect(200);
@ -154,7 +154,7 @@ describe('Authentication API canary', function () {
}); });
it('check invalid invite', async function () { it('check invalid invite', async function () {
const res = await request const res = await agent
.get(`authentication/invitation?email=notinvited@example.org`) .get(`authentication/invitation?email=notinvited@example.org`)
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200); .expect(200);
@ -163,7 +163,7 @@ describe('Authentication API canary', function () {
}); });
it('try to accept without invite', function () { it('try to accept without invite', function () {
return request return agent
.post('authentication/invitation') .post('authentication/invitation')
.send({ .send({
invitation: [{ invitation: [{
@ -178,7 +178,7 @@ describe('Authentication API canary', function () {
}); });
it('try to accept with invite and existing email address', function () { it('try to accept with invite and existing email address', function () {
return request return agent
.post('authentication/invitation') .post('authentication/invitation')
.send({ .send({
invitation: [{ invitation: [{
@ -193,7 +193,7 @@ describe('Authentication API canary', function () {
}); });
it('try to accept with invite', async function () { it('try to accept with invite', async function () {
const res = await request const res = await agent
.post('authentication/invitation') .post('authentication/invitation')
.send({ .send({
invitation: [{ invitation: [{
@ -214,10 +214,10 @@ describe('Authentication API canary', function () {
const user = testUtils.DataGenerator.forModel.users[0]; const user = testUtils.DataGenerator.forModel.users[0];
before(async function () { before(async function () {
request = await framework.getAgent('/ghost/api/canary/admin/'); agent = await framework.getAgent('/ghost/api/canary/admin/');
// NOTE: this order of fixture initialization boggles me. Ideally should not depend on agent/login sequence // NOTE: this order of fixture initialization boggles me. Ideally should not depend on agent/login sequence
await framework.initFixtures('invites'); await framework.initFixtures('invites');
await request.loginAsOwner(); await agent.loginAsOwner();
}); });
after(async function () { after(async function () {
@ -242,7 +242,7 @@ describe('Authentication API canary', function () {
password: ownerUser.get('password') password: ownerUser.get('password')
}); });
const res = await request.put('authentication/passwordreset') const res = await agent.put('authentication/passwordreset')
.set('Accept', 'application/json') .set('Accept', 'application/json')
.send({ .send({
passwordreset: [{ passwordreset: [{
@ -261,7 +261,7 @@ describe('Authentication API canary', function () {
}); });
it('reset password: invalid token', async function () { it('reset password: invalid token', async function () {
const res = await request const res = await agent
.put('authentication/passwordreset') .put('authentication/passwordreset')
.set('Accept', 'application/json') .set('Accept', 'application/json')
.send({ .send({
@ -295,7 +295,7 @@ describe('Authentication API canary', function () {
password: ownerUser.get('password') password: ownerUser.get('password')
}); });
const res = await request const res = await agent
.put('authentication/passwordreset') .put('authentication/passwordreset')
.set('Accept', 'application/json') .set('Accept', 'application/json')
.send({ .send({
@ -326,7 +326,7 @@ describe('Authentication API canary', function () {
password: 'invalid_password' password: 'invalid_password'
}); });
const res = await request const res = await agent
.put('authentication/passwordreset') .put('authentication/passwordreset')
.set('Accept', 'application/json') .set('Accept', 'application/json')
.send({ .send({
@ -350,7 +350,7 @@ describe('Authentication API canary', function () {
}); });
it('reset password: generate reset token', async function () { it('reset password: generate reset token', async function () {
const res = await request const res = await agent
.post('authentication/passwordreset') .post('authentication/passwordreset')
.set('Accept', 'application/json') .set('Accept', 'application/json')
.send({ .send({
@ -371,10 +371,10 @@ describe('Authentication API canary', function () {
describe('Reset all passwords', function () { describe('Reset all passwords', function () {
let sendEmail; let sendEmail;
before(async function () { before(async function () {
request = await framework.getAgent('/ghost/api/canary/admin/'); agent = await framework.getAgent('/ghost/api/canary/admin/');
// NOTE: this order of fixture initialization boggles me. Ideally should not depend on agent/login sequence // NOTE: this order of fixture initialization boggles me. Ideally should not depend on agent/login sequence
await framework.initFixtures('invites'); await framework.initFixtures('invites');
await request.loginAsOwner(); await agent.loginAsOwner();
}); });
after(async function () { after(async function () {
@ -390,7 +390,7 @@ describe('Authentication API canary', function () {
}); });
it('reset all passwords returns 200', async function () { it('reset all passwords returns 200', async function () {
const res = await request.post('authentication/reset_all_passwords') const res = await agent.post('authentication/reset_all_passwords')
.set('Accept', 'application/json') .set('Accept', 'application/json')
.send({}) .send({})
.expect(200); .expect(200);

View File

@ -4,14 +4,14 @@ const {any, stringMatching} = require('expect');
const framework = require('../../../../utils/e2e-framework'); const framework = require('../../../../utils/e2e-framework');
describe('Config API', function () { describe('Config API', function () {
let request; let agent;
before(async function () { before(async function () {
request = await framework.getAgent('/ghost/api/canary/admin/'); agent = await framework.getAgent('/ghost/api/canary/admin/');
}); });
it('can retrieve config and all expected properties', async function () { it('can retrieve config and all expected properties', async function () {
const res = await request const res = await agent
.get('site/'); .get('site/');
expect(res.body.site).to.matchSnapshot({ expect(res.body.site).to.matchSnapshot({