0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-01 02:41:39 -05:00

Refactored regression tests to use async/await

refs https://github.com/TryGhost/Toolbox/issues/138

- Final batch of the refactor to async/await syntax.  Doing these refactors before modifying "testUtils.startGhost" everywhere to boot only with the backend
This commit is contained in:
Naz 2021-11-24 16:38:51 +04:00 committed by naz
parent 4cdcb16e49
commit 222273b66b
12 changed files with 132 additions and 234 deletions

View file

@ -1262,49 +1262,33 @@ describe('Settings API (canary)', function () {
});
describe('As Admin', function () {
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create admin
return testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'admin+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[0].name
});
})
.then(function (admin) {
request.user = admin;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
// by default we login with the owner
return localUtils.doAuth(request);
});
// create admin
const admin = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'admin+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[0].name
});
request.user = admin;
// by default we login with the owner
await localUtils.doAuth(request);
});
});
describe('As Editor', function () {
let editor;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
// create editor
request.user = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[1].name
});
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create editor
return testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[1].name
});
})
.then(function (_user1) {
editor = _user1;
request.user = editor;
// by default we login with the owner
return localUtils.doAuth(request);
});
// by default we login with the owner
await localUtils.doAuth(request);
});
it('should not be able to edit settings', function () {
@ -1346,24 +1330,18 @@ describe('Settings API (canary)', function () {
});
describe('As Author', function () {
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create author
return testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+2@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[2].name
});
})
.then(function (author) {
request.user = author;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
// by default we login with the owner
return localUtils.doAuth(request);
});
// create author
request.user = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+2@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[2].name
});
// by default we login with the owner
await localUtils.doAuth(request);
});
it('should not be able to edit settings', function () {

View file

@ -9,14 +9,10 @@ describe('Authors Content API', function () {
const validKey = localUtils.getValidKey();
let request;
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
return testUtils.initFixtures('owner:post', 'users:no-owner', 'user:inactive', 'posts', 'api_keys');
});
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('owner:post', 'users:no-owner', 'user:inactive', 'posts', 'api_keys');
});
afterEach(function () {

View file

@ -10,14 +10,10 @@ let request;
describe('api/canary/content/pages', function () {
const key = localUtils.getValidKey();
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
afterEach(function () {

View file

@ -11,14 +11,10 @@ let request;
describe('api/canary/content/tags', function () {
const validKey = localUtils.getValidKey();
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
afterEach(function () {

View file

@ -721,49 +721,33 @@ describe('Settings API (v2)', function () {
});
describe('As Admin', function () {
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create admin
return testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'admin+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[0].name
});
})
.then(function (admin) {
request.user = admin;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
// by default we login with the owner
return localUtils.doAuth(request);
});
// create admin
const admin = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'admin+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[0].name
});
request.user = admin;
// by default we login with the owner
await localUtils.doAuth(request);
});
});
describe('As Editor', function () {
let editor;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
// create editor
request.user = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[1].name
});
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create editor
return testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[1].name
});
})
.then(function (_user1) {
editor = _user1;
request.user = editor;
// by default we login with the owner
return localUtils.doAuth(request);
});
// by default we login with the owner
await localUtils.doAuth(request);
});
it('should not be able to edit settings', function () {
@ -805,24 +789,18 @@ describe('Settings API (v2)', function () {
});
describe('As Author', function () {
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create author
return testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+2@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[2].name
});
})
.then(function (author) {
request.user = author;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
// by default we login with the owner
return localUtils.doAuth(request);
});
// create author
request.user = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+2@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[2].name
});
// by default we login with the owner
await localUtils.doAuth(request);
});
it('should not be able to edit settings', function () {

View file

@ -9,14 +9,10 @@ describe('Authors Content API', function () {
const validKey = localUtils.getValidKey();
let request;
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
return testUtils.initFixtures('owner:post', 'users:no-owner', 'user:inactive', 'posts', 'api_keys');
});
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('owner:post', 'users:no-owner', 'user:inactive', 'posts', 'api_keys');
});
afterEach(function () {

View file

@ -9,14 +9,10 @@ const config = require('../../../../../core/shared/config');
let request;
describe('api/v2/content/pages', function () {
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
afterEach(function () {

View file

@ -9,14 +9,10 @@ const config = require('../../../../../core/shared/config');
let request;
describe('api/v2/content/tags', function () {
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
afterEach(function () {

View file

@ -715,49 +715,33 @@ describe('Settings API (v3)', function () {
});
describe('As Admin', function () {
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create admin
return testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'admin+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[0].name
});
})
.then(function (admin) {
request.user = admin;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
// by default we login with the owner
return localUtils.doAuth(request);
});
// create admin
const admin = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'admin+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[0].name
});
request.user = admin;
// by default we login with the owner
await localUtils.doAuth(request);
});
});
describe('As Editor', function () {
let editor;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
// create editor
request.user = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[1].name
});
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create editor
return testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+1@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[1].name
});
})
.then(function (_user1) {
editor = _user1;
request.user = editor;
// by default we login with the owner
return localUtils.doAuth(request);
});
// by default we login with the owner
await localUtils.doAuth(request);
});
it('should not be able to edit settings', function () {
@ -799,24 +783,18 @@ describe('Settings API (v3)', function () {
});
describe('As Author', function () {
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create author
return testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+2@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[2].name
});
})
.then(function (author) {
request.user = author;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
// by default we login with the owner
return localUtils.doAuth(request);
});
// create author
request.user = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+2@ghost.org'}),
role: testUtils.DataGenerator.Content.roles[2].name
});
// by default we login with the owner
await localUtils.doAuth(request);
});
it('should not be able to edit settings', function () {

View file

@ -9,14 +9,10 @@ describe('Authors Content API', function () {
const validKey = localUtils.getValidKey();
let request;
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
return testUtils.initFixtures('owner:post', 'users:no-owner', 'user:inactive', 'posts', 'api_keys');
});
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('owner:post', 'users:no-owner', 'user:inactive', 'posts', 'api_keys');
});
afterEach(function () {

View file

@ -10,14 +10,10 @@ let request;
describe('api/v3/content/pages', function () {
const key = localUtils.getValidKey();
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
afterEach(function () {

View file

@ -11,14 +11,10 @@ let request;
describe('api/v3/content/tags', function () {
const validKey = localUtils.getValidKey();
before(function () {
return testUtils.startGhost()
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
});
afterEach(function () {