mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Added test coverage for collection updates
refs https://github.com/TryGhost/Team/issues/3170 - When the collection filter is updated the collection's posts should be updated automatically.
This commit is contained in:
parent
67fdff479b
commit
3599cfdd7a
@ -181,7 +181,7 @@ describe('CollectionsService', function () {
|
||||
assert.equal(collection.type, 'automatic', 'Collection should be automatic');
|
||||
assert.equal(collection.filter, 'featured:true', 'Collection should have the correct filter');
|
||||
|
||||
assert.equal(collection.posts.length, 1, 'Collection should have one post');
|
||||
assert.equal(collection.posts.length, 2, 'Collection should have two posts');
|
||||
});
|
||||
|
||||
it('Populates collection when the type is changed to automatic and filter is present', async function () {
|
||||
@ -200,8 +200,30 @@ describe('CollectionsService', function () {
|
||||
filter: 'featured:true'
|
||||
});
|
||||
|
||||
assert.equal(automaticCollection?.posts.length, 1, 'Collection should have one post');
|
||||
assert.equal(automaticCollection?.posts.length, 2, 'Collection should have two featured post');
|
||||
assert.equal(automaticCollection?.posts[0].id, 'post-3-featured', 'Collection should have the correct post');
|
||||
});
|
||||
|
||||
it('Updates the automatic collection posts when the filter is changed', async function () {
|
||||
let collection = await collectionsService.createCollection({
|
||||
title: 'I am automatic',
|
||||
description: 'testing automatic collection',
|
||||
type: 'automatic',
|
||||
filter: 'featured:true'
|
||||
});
|
||||
|
||||
assert.equal(collection?.type, 'automatic', 'Collection should be automatic');
|
||||
assert.equal(collection?.posts.length, 2, 'Collection should have two featured post');
|
||||
assert.equal(collection?.posts[0].id, 'post-3-featured', 'Collection should have the correct post');
|
||||
assert.equal(collection?.posts[1].id, 'post-4-featured', 'Collection should have the correct post');
|
||||
|
||||
let updatedCollection = await collectionsService.edit({
|
||||
id: collection.id,
|
||||
filter: 'slug:post-2'
|
||||
});
|
||||
|
||||
assert.equal(updatedCollection?.posts.length, 1, 'Collection should have one post');
|
||||
assert.equal(updatedCollection?.posts[0].id, 'post-2', 'Collection should have the correct post');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -2,6 +2,7 @@ import {InMemoryRepository} from '@tryghost/in-memory-repository';
|
||||
|
||||
type CollectionPost = {
|
||||
id: string;
|
||||
slug: string;
|
||||
featured: boolean;
|
||||
published_at: Date;
|
||||
deleted: boolean;
|
||||
@ -11,6 +12,7 @@ export class PostsRepositoryInMemory extends InMemoryRepository<string, Collecti
|
||||
protected toPrimitive(entity: CollectionPost): object {
|
||||
return {
|
||||
id: entity.id,
|
||||
slug: entity.slug,
|
||||
featured: entity.featured,
|
||||
published_at: entity.published_at
|
||||
};
|
||||
|
6
ghost/collections/test/fixtures/posts.ts
vendored
6
ghost/collections/test/fixtures/posts.ts
vendored
@ -16,4 +16,10 @@ export const posts = [{
|
||||
slug: 'featured-post-3',
|
||||
featured: true,
|
||||
published_at: new Date('2023-05-25T07:21:07.447Z')
|
||||
}, {
|
||||
id: 'post-4-featured',
|
||||
title: 'Featured Post 4',
|
||||
slug: 'featured-post-4',
|
||||
featured: true,
|
||||
published_at: new Date('2023-05-15T07:21:07.447Z')
|
||||
}];
|
||||
|
Loading…
Reference in New Issue
Block a user