mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
Refactored scheduling tests setup using async/await
refs https://github.com/TryGhost/Team/issues/694 - The previous `.then` chaining was outdated and was causing 2x ghost instance initialization per test suite - With a refactor there's only one intance initialization per suite (saves running time!) and we use more readable async/await syntax, which should make things more maintainable
This commit is contained in:
parent
46ef52cc7d
commit
ba50241fde
@ -27,68 +27,62 @@ describe('Canary Schedules API', function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(() => {
|
||||
request = supertest.agent(config.get('url'));
|
||||
});
|
||||
});
|
||||
before(async function () {
|
||||
await ghost();
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function () {
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'first'
|
||||
}));
|
||||
request = supertest.agent(config.get('url'));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'second'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'first'
|
||||
}));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'third'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'second'
|
||||
}));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fourth'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'third'
|
||||
}));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fifth',
|
||||
type: 'page'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fourth'
|
||||
}));
|
||||
|
||||
return Promise.mapSeries(resources, function (post) {
|
||||
return models.Post.add(post, {context: {internal: true}});
|
||||
}).then(function (result) {
|
||||
result.length.should.eql(5);
|
||||
});
|
||||
});
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fifth',
|
||||
type: 'page'
|
||||
}));
|
||||
|
||||
const result = await Promise.mapSeries(resources, function (post) {
|
||||
return models.Post.add(post, {context: {internal: true}});
|
||||
});
|
||||
|
||||
result.length.should.eql(5);
|
||||
});
|
||||
|
||||
describe('publish', function () {
|
||||
|
@ -27,68 +27,62 @@ describe('v2 Schedules API', function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(() => {
|
||||
request = supertest.agent(config.get('url'));
|
||||
});
|
||||
});
|
||||
before(async function () {
|
||||
await ghost();
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function () {
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'first'
|
||||
}));
|
||||
request = supertest.agent(config.get('url'));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'second'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'first'
|
||||
}));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'third'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'second'
|
||||
}));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fourth'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'third'
|
||||
}));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fifth',
|
||||
type: 'page'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fourth'
|
||||
}));
|
||||
|
||||
return Promise.mapSeries(resources, function (post) {
|
||||
return models.Post.add(post, {context: {internal: true}});
|
||||
}).then(function (result) {
|
||||
result.length.should.eql(5);
|
||||
});
|
||||
});
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fifth',
|
||||
type: 'page'
|
||||
}));
|
||||
|
||||
const result = await Promise.mapSeries(resources, function (post) {
|
||||
return models.Post.add(post, {context: {internal: true}});
|
||||
});
|
||||
|
||||
result.length.should.eql(5);
|
||||
});
|
||||
|
||||
describe('publish', function () {
|
||||
|
@ -27,68 +27,62 @@ describe('v3 Schedules API', function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(() => {
|
||||
request = supertest.agent(config.get('url'));
|
||||
});
|
||||
});
|
||||
before(async function () {
|
||||
await ghost();
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function () {
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'first'
|
||||
}));
|
||||
request = supertest.agent(config.get('url'));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'second'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'first'
|
||||
}));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'third'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'second'
|
||||
}));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fourth'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'third'
|
||||
}));
|
||||
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fifth',
|
||||
type: 'page'
|
||||
}));
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().subtract(10, 'minute').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fourth'
|
||||
}));
|
||||
|
||||
return Promise.mapSeries(resources, function (post) {
|
||||
return models.Post.add(post, {context: {internal: true}});
|
||||
}).then(function (result) {
|
||||
result.length.should.eql(5);
|
||||
});
|
||||
});
|
||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||
created_by: testUtils.existingData.users[0].id,
|
||||
author_id: testUtils.existingData.users[0].id,
|
||||
published_by: testUtils.existingData.users[0].id,
|
||||
published_at: moment().add(30, 'seconds').toDate(),
|
||||
status: 'scheduled',
|
||||
slug: 'fifth',
|
||||
type: 'page'
|
||||
}));
|
||||
|
||||
const result = await Promise.mapSeries(resources, function (post) {
|
||||
return models.Post.add(post, {context: {internal: true}});
|
||||
});
|
||||
|
||||
result.length.should.eql(5);
|
||||
});
|
||||
|
||||
describe('publish', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user