mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
Added e2e test coverage for bulk collection edits
refs https://github.com/TryGhost/Arch/issues/16 - Makes sure post bulk actions also update collection posts
This commit is contained in:
parent
aaf0998129
commit
7464dbc1af
@ -1,3 +1,4 @@
|
||||
const DomainEvents = require('@tryghost/domain-events');
|
||||
const {agentProvider, fixtureManager, mockManager} = require('../../utils/e2e-framework');
|
||||
const models = require('../../../core/server/models');
|
||||
const assert = require('assert/strict');
|
||||
@ -28,6 +29,10 @@ describe('Posts Bulk API', function () {
|
||||
|
||||
assert(amount > 0, 'Expect at least one post to be affected for this test to work');
|
||||
|
||||
let featuredCollection = await models.Collection.findPage({filter: 'slug:featured', limit: 1, withRelated: ['posts']});
|
||||
let featuredCollectionPostsAmount = featuredCollection.data[0].toJSON().posts.length;
|
||||
assert(featuredCollectionPostsAmount > 0, 'Expect to have multiple featured collection posts');
|
||||
|
||||
const response = await agent
|
||||
.put('/posts/bulk/?filter=' + encodeURIComponent(filter))
|
||||
.body({
|
||||
@ -38,12 +43,18 @@ describe('Posts Bulk API', function () {
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot();
|
||||
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
assert.equal(response.body.bulk.meta.stats.successful, amount, `Expect all matching posts (${amount}) to be changed`);
|
||||
|
||||
// Fetch all posts and check if they are featured
|
||||
const posts = await models.Post.findAll({filter, status: 'all'});
|
||||
assert.equal(posts.length, amount, `Expect all matching posts (${amount}) to be changed`);
|
||||
|
||||
featuredCollection = await models.Collection.findPage({filter: 'slug:featured', limit: 1, withRelated: ['posts']});
|
||||
featuredCollectionPostsAmount = featuredCollection.data[0].toJSON().posts.length;
|
||||
assert.equal(featuredCollectionPostsAmount, amount, 'Expect to have same amount featured collection posts as changed');
|
||||
|
||||
for (const post of posts) {
|
||||
assert(post.get('featured') === true, `Expect post ${post.id} to be featured`);
|
||||
}
|
||||
@ -58,6 +69,10 @@ describe('Posts Bulk API', function () {
|
||||
|
||||
assert(amount > 0, 'Expect at least one post to be affected for this test to work');
|
||||
|
||||
let featuredCollection = await models.Collection.findPage({filter: 'slug:featured', limit: 1, withRelated: ['posts']});
|
||||
let featuredCollectionPostsAmount = featuredCollection.data[0].toJSON().posts.length;
|
||||
assert(featuredCollectionPostsAmount > 0, 'Expect to have multiple featured collection posts');
|
||||
|
||||
const response = await agent
|
||||
.put('/posts/bulk/?filter=' + encodeURIComponent(filter))
|
||||
.body({
|
||||
@ -68,12 +83,18 @@ describe('Posts Bulk API', function () {
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot();
|
||||
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
assert.equal(response.body.bulk.meta.stats.successful, amount, `Expect all matching posts (${amount}) to be changed`);
|
||||
|
||||
// Fetch all posts and check if they are featured
|
||||
const posts = await models.Post.findAll({filter, status: 'all'});
|
||||
assert.equal(posts.length, amount, `Expect all matching posts (${amount}) to be changed`);
|
||||
|
||||
featuredCollection = await models.Collection.findPage({filter: 'slug:featured', limit: 1, withRelated: ['posts']});
|
||||
featuredCollectionPostsAmount = featuredCollection.data[0].toJSON().posts.length;
|
||||
assert.equal(featuredCollectionPostsAmount, 0, 'Expect to have no featured collection posts');
|
||||
|
||||
for (const post of posts) {
|
||||
assert(post.get('featured') === false, `Expect post ${post.id} to be unfeatured`);
|
||||
}
|
||||
@ -293,6 +314,13 @@ describe('Posts Bulk API', function () {
|
||||
|
||||
assert(amount > 0, 'Expect at least one post to be affected for this test to work');
|
||||
|
||||
await agent
|
||||
.get('posts/?collection=latest')
|
||||
.expectStatus(200)
|
||||
.expect((res) => {
|
||||
assert(res.body.posts.length > 0, 'Expect latest collection to have some posts');
|
||||
});
|
||||
|
||||
const response = await agent
|
||||
.delete('/posts/?filter=' + encodeURIComponent(filter))
|
||||
.expectStatus(200)
|
||||
|
Loading…
Reference in New Issue
Block a user