Added bulk post unpublishing test

refs https://github.com/TryGhost/Team/issues/2925
This commit is contained in:
Simon Backx 2023-04-27 14:58:27 +02:00
parent 1ff71dc36c
commit 9fc98417b5
2 changed files with 39 additions and 0 deletions

View File

@ -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 [],
},
},
}
`;

View File

@ -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 () {