mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Refactored posts regressions suites to use common initialization syntax
refs https://github.com/TryGhost/Toolbox/issues/138 - Using asycn/await syntax is way more readable and allows to identify further reusable patterns in test initialization. This refactor also served as an exploreation around how the code looks like at this point
This commit is contained in:
parent
5e931e2e37
commit
e715c5b82d
6 changed files with 34 additions and 78 deletions
|
@ -8,20 +8,14 @@ const config = require('../../../../../core/shared/config');
|
|||
const models = require('../../../../../core/server/models');
|
||||
const localUtils = require('./utils');
|
||||
const ghost = testUtils.startGhost;
|
||||
let request;
|
||||
|
||||
describe('Posts API (canary)', function () {
|
||||
let ghostServer;
|
||||
let request;
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function (_ghostServer) {
|
||||
ghostServer = _ghostServer;
|
||||
request = supertest.agent(config.get('url'));
|
||||
})
|
||||
.then(function () {
|
||||
return localUtils.doAuth(request, 'users:extra', 'posts', 'emails', 'members');
|
||||
});
|
||||
before(async function () {
|
||||
await ghost();
|
||||
request = supertest.agent(config.get('url'));
|
||||
await localUtils.doAuth(request, 'users:extra', 'posts', 'emails', 'members');
|
||||
});
|
||||
|
||||
describe('Browse', function () {
|
||||
|
|
|
@ -11,17 +11,14 @@ const urlUtils = require('../../../../utils/urlUtils');
|
|||
const config = require('../../../../../core/shared/config');
|
||||
|
||||
const ghost = testUtils.startGhost;
|
||||
let request;
|
||||
|
||||
describe('api/canary/content/posts', function () {
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function () {
|
||||
request = supertest.agent(config.get('url'));
|
||||
})
|
||||
.then(function () {
|
||||
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
||||
});
|
||||
let request;
|
||||
|
||||
before(async function () {
|
||||
await ghost();
|
||||
request = supertest.agent(config.get('url'));
|
||||
await testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
|
|
@ -7,24 +7,15 @@ const config = require('../../../../../core/shared/config');
|
|||
const models = require('../../../../../core/server/models');
|
||||
const localUtils = require('./utils');
|
||||
const ghost = testUtils.startGhost;
|
||||
let request;
|
||||
|
||||
describe('Posts API (v2)', function () {
|
||||
let ghostServer;
|
||||
let request;
|
||||
let ownerCookie;
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function (_ghostServer) {
|
||||
ghostServer = _ghostServer;
|
||||
request = supertest.agent(config.get('url'));
|
||||
})
|
||||
.then(function () {
|
||||
return localUtils.doAuth(request, 'users:extra', 'posts');
|
||||
})
|
||||
.then(function (cookie) {
|
||||
ownerCookie = cookie;
|
||||
});
|
||||
before(async function () {
|
||||
await ghost();
|
||||
request = supertest.agent(config.get('url'));
|
||||
ownerCookie = await localUtils.doAuth(request, 'users:extra', 'posts');
|
||||
});
|
||||
|
||||
describe('Browse', function () {
|
||||
|
|
|
@ -13,17 +13,14 @@ const urlUtils = require('../../../../utils/urlUtils');
|
|||
const config = require('../../../../../core/shared/config');
|
||||
|
||||
const ghost = testUtils.startGhost;
|
||||
let request;
|
||||
|
||||
describe('api/v2/content/posts', function () {
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function () {
|
||||
request = supertest.agent(config.get('url'));
|
||||
})
|
||||
.then(function () {
|
||||
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
||||
});
|
||||
let request;
|
||||
|
||||
before(async function () {
|
||||
await ghost();
|
||||
request = supertest.agent(config.get('url'));
|
||||
await testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
@ -214,11 +211,6 @@ describe('api/v2/content/posts', function () {
|
|||
let paidPost;
|
||||
let membersPostWithPaywallCard;
|
||||
|
||||
before(function () {
|
||||
// NOTE: ideally this would be set through Admin API request not a stub
|
||||
sinon.stub(labs, 'isSet').withArgs('members').returns(true);
|
||||
});
|
||||
|
||||
before (function () {
|
||||
publicPost = testUtils.DataGenerator.forKnex.createPost({
|
||||
slug: 'free-to-see',
|
||||
|
|
|
@ -8,24 +8,16 @@ const config = require('../../../../../core/shared/config');
|
|||
const models = require('../../../../../core/server/models');
|
||||
const localUtils = require('./utils');
|
||||
const ghost = testUtils.startGhost;
|
||||
let request;
|
||||
|
||||
describe('Posts API (v3)', function () {
|
||||
let ghostServer;
|
||||
let request;
|
||||
let ownerCookie;
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function (_ghostServer) {
|
||||
ghostServer = _ghostServer;
|
||||
request = supertest.agent(config.get('url'));
|
||||
})
|
||||
.then(function () {
|
||||
return localUtils.doAuth(request, 'users:extra', 'posts', 'emails');
|
||||
})
|
||||
.then(function (cookie) {
|
||||
ownerCookie = cookie;
|
||||
});
|
||||
before(async function () {
|
||||
await ghost();
|
||||
request = supertest.agent(config.get('url'));
|
||||
|
||||
ownerCookie = await localUtils.doAuth(request, 'users:extra', 'posts', 'emails');
|
||||
});
|
||||
|
||||
describe('Browse', function () {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const moment = require('moment');
|
||||
const supertest = require('supertest');
|
||||
const _ = require('lodash');
|
||||
const labs = require('../../../../../core/shared/labs');
|
||||
const testUtils = require('../../../../utils');
|
||||
const localUtils = require('./utils');
|
||||
const configUtils = require('../../../../utils/configUtils');
|
||||
|
@ -11,17 +9,14 @@ const urlUtils = require('../../../../utils/urlUtils');
|
|||
const config = require('../../../../../core/shared/config');
|
||||
|
||||
const ghost = testUtils.startGhost;
|
||||
let request;
|
||||
|
||||
describe('api/v3/content/posts', function () {
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function () {
|
||||
request = supertest.agent(config.get('url'));
|
||||
})
|
||||
.then(function () {
|
||||
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
||||
});
|
||||
let request;
|
||||
|
||||
before(async function () {
|
||||
await ghost();
|
||||
request = supertest.agent(config.get('url'));
|
||||
await testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
@ -264,11 +259,6 @@ describe('api/v3/content/posts', function () {
|
|||
let paidPost;
|
||||
let membersPostWithPaywallCard;
|
||||
|
||||
before(function () {
|
||||
// NOTE: ideally this would be set through Admin API request not a stub
|
||||
sinon.stub(labs, 'isSet').withArgs('members').returns(true);
|
||||
});
|
||||
|
||||
before (function () {
|
||||
publicPost = testUtils.DataGenerator.forKnex.createPost({
|
||||
slug: 'free-to-see',
|
||||
|
|
Loading…
Add table
Reference in a new issue