From b123a9bb7761c2ee2660044d159734c90b49bafc Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 26 Apr 2022 16:52:44 +0800 Subject: [PATCH] Refactored multiauthor posts suite to async/await refs https://github.com/TryGhost/Toolbox/issues/268 - I'm about to rewrite it, so made the test suite slightly more readable to keep track of changes easier --- test/regression/models/model_posts.test.js | 30 ++++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/test/regression/models/model_posts.test.js b/test/regression/models/model_posts.test.js index e3b4111368..22f404d34f 100644 --- a/test/regression/models/model_posts.test.js +++ b/test/regression/models/model_posts.test.js @@ -1660,30 +1660,26 @@ describe('Post Model', function () { describe('Multiauthor Posts', function () { before(testUtils.teardownDb); - after(function () { - return testUtils.teardownDb() - .then(function () { - return testUtils.setup('users:roles')(); - }); + after(async function () { + await testUtils.teardownDb() + await testUtils.setup('users:roles')(); }); before(testUtils.setup('posts:mu')); - it('can reassign multiple posts by author', function (done) { + it('can reassign multiple posts by author', async function () { // We're going to delete all posts by user 1 const authorData = {id: testUtils.DataGenerator.Content.users[0].id}; - models.Post.findAll({context: {internal: true}}).then(function (found) { - // There are 10 posts created by posts:mu fixture - found.length.should.equal(10); - return models.Post.reassignByAuthor(authorData); - }).then(function () { - return models.Post.findAll({context: {internal: true}}); - }).then(function (found) { - // All 10 should remain - found.length.should.equal(10); - done(); - }).catch(done); + const preReassignPosts = await models.Post.findAll({context: {internal: true}}); + // There are 10 posts created by posts:mu fixture + preReassignPosts.length.should.equal(10); + + await models.Post.reassignByAuthor(authorData); + + const postReassignPosts = await models.Post.findAll({context: {internal: true}}); + // All 10 should remain + postReassignPosts.length.should.equal(10); }); });