From 9fc98417b50ec53f1e378cc0fd52b6dd53cd1dc3 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Thu, 27 Apr 2023 14:58:27 +0200 Subject: [PATCH] Added bulk post unpublishing test refs https://github.com/TryGhost/Team/issues/2925 --- .../__snapshots__/posts-bulk.test.js.snap | 15 ++++++++++++ .../test/e2e-api/admin/posts-bulk.test.js | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/posts-bulk.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/posts-bulk.test.js.snap index d55d41abf1..cf2db79d70 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/posts-bulk.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/posts-bulk.test.js.snap @@ -113,3 +113,18 @@ Object { }, } `; + +exports[`Posts Bulk API Edit Can unpublish posts 1: [body] 1`] = ` +Object { + "bulk": Object { + "meta": Object { + "errors": Array [], + "stats": Object { + "successful": 11, + "unsuccessful": 0, + }, + "unsuccessfulData": Array [], + }, + }, +} +`; diff --git a/ghost/core/test/e2e-api/admin/posts-bulk.test.js b/ghost/core/test/e2e-api/admin/posts-bulk.test.js index 7e5dd9a6bc..7f812adacd 100644 --- a/ghost/core/test/e2e-api/admin/posts-bulk.test.js +++ b/ghost/core/test/e2e-api/admin/posts-bulk.test.js @@ -255,6 +255,30 @@ describe('Posts Bulk API', function () { assert(tags.find(t => t.id === newTagModel.id), `Expect post ${post.id} to have new tag ${newTagModel.id}`); } }); + + it('Can unpublish posts', async function () { + const filter = 'status:[published]'; + const changedPosts = await models.Post.findPage({filter, limit: 1, status: 'all'}); + const amount = changedPosts.meta.pagination.total; + + assert(amount > 0, 'Expect at least one post to be affected for this test to work'); + + const response = await agent + .put('/posts/bulk/?filter=' + encodeURIComponent(filter)) + .body({ + bulk: { + action: 'unpublish' + } + }) + .expectStatus(200) + .matchBodySnapshot(); + + assert.equal(response.body.bulk.meta.stats.successful, amount, `Expect all matching posts (${amount}) to be unpublished, got ${response.body.bulk.meta.stats.successful} instead`); + + // Fetch all posts and check if they are unpublished + const posts = await models.Post.findAll({filter, status: 'all'}); + assert.equal(posts.length, 0, `Expect all matching posts (${amount}) to be unpublished`); + }); }); describe('Delete', function () {