2023-06-21 11:56:59 +03:00
|
|
|
const assert = require('assert/strict');
|
2023-05-16 10:30:31 +03:00
|
|
|
const {
|
|
|
|
agentProvider,
|
|
|
|
fixtureManager,
|
2023-05-17 09:55:07 +03:00
|
|
|
mockManager,
|
|
|
|
matchers
|
2023-05-16 10:30:31 +03:00
|
|
|
} = require('../../utils/e2e-framework');
|
2023-08-22 10:16:54 +03:00
|
|
|
const DomainEvents = require('@tryghost/domain-events/lib/DomainEvents');
|
2023-05-17 09:55:07 +03:00
|
|
|
const {
|
|
|
|
anyContentVersion,
|
|
|
|
anyEtag,
|
2023-05-17 17:59:03 +03:00
|
|
|
anyErrorId,
|
2023-05-17 09:55:07 +03:00
|
|
|
anyLocationFor,
|
2023-05-24 12:56:41 +03:00
|
|
|
anyObjectId,
|
2023-06-01 07:17:00 +03:00
|
|
|
anyISODateTime,
|
2023-07-21 10:29:37 +03:00
|
|
|
anyString,
|
|
|
|
anyUuid,
|
|
|
|
anyArray,
|
|
|
|
anyObject
|
2023-05-17 09:55:07 +03:00
|
|
|
} = matchers;
|
|
|
|
|
|
|
|
const matchCollection = {
|
2023-05-24 12:56:41 +03:00
|
|
|
id: anyObjectId,
|
|
|
|
created_at: anyISODateTime,
|
|
|
|
updated_at: anyISODateTime
|
2023-05-17 09:55:07 +03:00
|
|
|
};
|
2023-05-16 10:30:31 +03:00
|
|
|
|
2023-07-24 12:08:46 +03:00
|
|
|
const tagSnapshotMatcher = {
|
|
|
|
id: anyObjectId,
|
|
|
|
created_at: anyISODateTime,
|
|
|
|
updated_at: anyISODateTime
|
|
|
|
};
|
|
|
|
|
2023-07-21 10:29:37 +03:00
|
|
|
const matchPostShallowIncludes = {
|
|
|
|
id: anyObjectId,
|
|
|
|
uuid: anyUuid,
|
|
|
|
comment_id: anyString,
|
|
|
|
url: anyString,
|
|
|
|
authors: anyArray,
|
|
|
|
primary_author: anyObject,
|
2023-07-25 16:19:19 +03:00
|
|
|
tags: anyArray,
|
2023-07-21 10:29:37 +03:00
|
|
|
primary_tag: anyObject,
|
2023-07-25 16:19:19 +03:00
|
|
|
tiers: anyArray,
|
2023-07-21 10:29:37 +03:00
|
|
|
created_at: anyISODateTime,
|
|
|
|
updated_at: anyISODateTime,
|
|
|
|
published_at: anyISODateTime,
|
|
|
|
post_revisions: anyArray
|
2023-07-18 14:50:18 +03:00
|
|
|
};
|
2023-06-13 13:02:01 +03:00
|
|
|
|
2023-05-17 09:55:07 +03:00
|
|
|
describe('Collections API', function () {
|
2023-05-16 10:30:31 +03:00
|
|
|
let agent;
|
|
|
|
|
|
|
|
before(async function () {
|
2023-06-19 17:40:15 +03:00
|
|
|
mockManager.mockLabsEnabled('collections');
|
2023-05-16 10:30:31 +03:00
|
|
|
agent = await agentProvider.getAdminAPIAgent();
|
2023-06-01 12:55:48 +03:00
|
|
|
await fixtureManager.init('users', 'posts');
|
2023-05-16 10:30:31 +03:00
|
|
|
await agent.loginAsOwner();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
mockManager.restore();
|
|
|
|
});
|
|
|
|
|
2023-07-19 17:14:26 +03:00
|
|
|
describe('Browse', function () {
|
|
|
|
it('Can browse Collections', async function () {
|
|
|
|
await agent
|
|
|
|
.get('/collections/')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [
|
2023-07-25 16:19:19 +03:00
|
|
|
matchCollection,
|
|
|
|
matchCollection
|
2023-07-19 17:14:26 +03:00
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2023-07-25 17:30:40 +03:00
|
|
|
|
|
|
|
it('Can browse Collections and include the posts count', async function () {
|
|
|
|
await agent
|
|
|
|
.get('/collections/?include=count.posts')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [
|
|
|
|
{...matchCollection, count: {posts: 13}},
|
|
|
|
{...matchCollection, count: {posts: 2}}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2023-07-19 17:14:26 +03:00
|
|
|
});
|
|
|
|
|
2023-08-22 08:18:07 +03:00
|
|
|
describe('Read', function () {
|
|
|
|
it('Can read a Collection by id and slug', async function () {
|
|
|
|
const collection = {
|
|
|
|
title: 'Test Collection to Read'
|
|
|
|
};
|
|
|
|
|
|
|
|
const addResponse = await agent
|
|
|
|
.post('/collections/')
|
|
|
|
.body({
|
|
|
|
collections: [collection]
|
|
|
|
})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('collections')
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [matchCollection]
|
|
|
|
});
|
|
|
|
|
|
|
|
const collectionId = addResponse.body.collections[0].id;
|
|
|
|
|
|
|
|
const readResponse = await agent
|
|
|
|
.get(`/collections/${collectionId}/`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [matchCollection]
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(readResponse.body.collections[0].title, 'Test Collection to Read');
|
|
|
|
|
|
|
|
const collectionSlug = addResponse.body.collections[0].slug;
|
|
|
|
const readBySlugResponse = await agent
|
|
|
|
.get(`/collections/slug/${collectionSlug}/`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [matchCollection]
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(readBySlugResponse.body.collections[0].title, 'Test Collection to Read');
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.delete(`/collections/${collectionId}/`)
|
|
|
|
.expectStatus(204);
|
|
|
|
});
|
2023-05-17 18:14:13 +03:00
|
|
|
|
2023-08-22 08:18:07 +03:00
|
|
|
it('Can read a Collection by id and slug and include the post counts', async function () {
|
|
|
|
const {body: {collections: [collection]}} = await agent.get(`/collections/slug/featured/?include=count.posts`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [{
|
|
|
|
...matchCollection,
|
|
|
|
count: {
|
|
|
|
posts: 2
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
await agent.get(`/collections/${collection.id}/?include=count.posts`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [{
|
|
|
|
...matchCollection,
|
|
|
|
count: {
|
|
|
|
posts: 2
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
2023-07-25 17:30:40 +03:00
|
|
|
});
|
|
|
|
|
2023-06-01 12:55:48 +03:00
|
|
|
describe('Edit', function () {
|
2023-05-25 07:46:20 +03:00
|
|
|
let collectionToEdit;
|
|
|
|
|
|
|
|
before(async function () {
|
2023-05-25 07:39:48 +03:00
|
|
|
const collection = {
|
|
|
|
title: 'Test Collection to Edit'
|
|
|
|
};
|
|
|
|
|
|
|
|
const addResponse = await agent
|
|
|
|
.post('/collections/')
|
|
|
|
.body({
|
|
|
|
collections: [collection]
|
|
|
|
})
|
2023-05-25 07:46:20 +03:00
|
|
|
.expectStatus(201);
|
2023-05-25 07:39:48 +03:00
|
|
|
|
2023-05-25 07:46:20 +03:00
|
|
|
collectionToEdit = addResponse.body.collections[0];
|
|
|
|
});
|
2023-05-25 07:39:48 +03:00
|
|
|
|
2023-05-25 07:46:20 +03:00
|
|
|
it('Can edit a Collection', async function () {
|
2023-05-25 07:39:48 +03:00
|
|
|
const editResponse = await agent
|
2023-05-25 07:46:20 +03:00
|
|
|
.put(`/collections/${collectionToEdit.id}/`)
|
2023-05-25 07:39:48 +03:00
|
|
|
.body({
|
|
|
|
collections: [{
|
|
|
|
title: 'Test Collection Edited'
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [matchCollection]
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(editResponse.body.collections[0].title, 'Test Collection Edited');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Fails to edit unexistent Collection', async function () {
|
|
|
|
const unexistentID = '5951f5fca366002ebd5dbef7';
|
|
|
|
await agent
|
|
|
|
.put(`/collections/${unexistentID}/`)
|
|
|
|
.body({
|
|
|
|
collections: [{
|
|
|
|
id: unexistentID,
|
|
|
|
title: 'Editing unexistent Collection'
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.expectStatus(404)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
|
|
|
});
|
2023-05-17 17:59:03 +03:00
|
|
|
});
|
2023-05-19 16:29:23 +03:00
|
|
|
|
2023-08-22 08:18:07 +03:00
|
|
|
describe('Add', function () {
|
|
|
|
it('Can add a Collection', async function () {
|
|
|
|
const collection = {
|
|
|
|
title: 'Test Collection',
|
|
|
|
description: 'Test Collection Description'
|
|
|
|
};
|
|
|
|
|
|
|
|
const {body: {collections: [{id: collectionId}]}} = await agent
|
|
|
|
.post('/collections/')
|
|
|
|
.body({
|
|
|
|
collections: [collection]
|
|
|
|
})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('collections')
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [matchCollection]
|
|
|
|
});
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.delete(`/collections/${collectionId}/`)
|
|
|
|
.expectStatus(204);
|
|
|
|
});
|
2023-05-19 16:29:23 +03:00
|
|
|
});
|
2023-06-01 12:55:48 +03:00
|
|
|
|
2023-08-22 08:18:07 +03:00
|
|
|
describe('Delete', function () {
|
|
|
|
it('Can delete a Collection', async function () {
|
|
|
|
const collection = {
|
|
|
|
title: 'Test Collection to Delete'
|
|
|
|
};
|
|
|
|
|
|
|
|
const addResponse = await agent
|
|
|
|
.post('/collections/')
|
|
|
|
.body({
|
|
|
|
collections: [collection]
|
|
|
|
})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('collections')
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [matchCollection]
|
|
|
|
});
|
|
|
|
|
|
|
|
const collectionId = addResponse.body.collections[0].id;
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.delete(`/collections/${collectionId}/`)
|
|
|
|
.expectStatus(204)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot();
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.get(`/collections/${collectionId}/`)
|
|
|
|
.expectStatus(404)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Cannot delete a built in collection', async function () {
|
|
|
|
const builtInCollection = await agent
|
|
|
|
.get('/collections/?filter=slug:featured')
|
|
|
|
.expectStatus(200);
|
|
|
|
|
|
|
|
assert.ok(builtInCollection.body.collections);
|
|
|
|
assert.equal(builtInCollection.body.collections.length, 1);
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.delete(`/collections/${builtInCollection.body.collections[0].id}/`)
|
|
|
|
.expectStatus(405)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
id: anyErrorId,
|
|
|
|
context: anyString
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
2023-06-06 18:04:02 +03:00
|
|
|
});
|
|
|
|
|
2023-06-01 12:55:48 +03:00
|
|
|
describe('Automatic Collection Filtering', function () {
|
|
|
|
it('Creates an automatic Collection with a featured filter', async function () {
|
|
|
|
const collection = {
|
2023-06-29 00:50:50 +03:00
|
|
|
title: 'Test Featured Collection',
|
2023-07-25 16:19:19 +03:00
|
|
|
slug: 'featured-filter',
|
2023-06-01 12:55:48 +03:00
|
|
|
description: 'Test Collection Description',
|
|
|
|
type: 'automatic',
|
|
|
|
filter: 'featured:true'
|
|
|
|
};
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.post('/collections/')
|
|
|
|
.body({
|
|
|
|
collections: [collection]
|
|
|
|
})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('collections')
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
2023-07-25 16:19:19 +03:00
|
|
|
collections: [matchCollection]
|
|
|
|
});
|
|
|
|
|
|
|
|
await agent.get(`posts/?collection=${collection.slug}`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
posts: new Array(2).fill(matchPostShallowIncludes)
|
2023-06-01 12:55:48 +03:00
|
|
|
});
|
|
|
|
});
|
2023-06-05 10:59:49 +03:00
|
|
|
|
|
|
|
it('Creates an automatic Collection with a published_at filter', async function () {
|
|
|
|
const collection = {
|
|
|
|
title: 'Test Collection with published_at filter',
|
2023-07-25 16:19:19 +03:00
|
|
|
slug: 'published-at-filter',
|
2023-06-05 10:59:49 +03:00
|
|
|
description: 'Test Collection Description with published_at filter',
|
|
|
|
type: 'automatic',
|
|
|
|
filter: 'published_at:>=2022-05-25'
|
|
|
|
};
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.post('/collections/')
|
|
|
|
.body({
|
|
|
|
collections: [collection]
|
|
|
|
})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('collections')
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
2023-07-25 16:19:19 +03:00
|
|
|
collections: [matchCollection]
|
|
|
|
});
|
|
|
|
|
|
|
|
await agent.get(`posts/?collection=${collection.slug}`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
2023-07-26 11:30:31 +03:00
|
|
|
posts: new Array(9).fill(matchPostShallowIncludes)
|
2023-06-05 10:59:49 +03:00
|
|
|
});
|
|
|
|
});
|
2023-07-18 14:50:18 +03:00
|
|
|
|
2023-07-24 16:49:43 +03:00
|
|
|
it('Creates an automatic Collection with a tags filter', async function () {
|
2023-07-18 14:50:18 +03:00
|
|
|
const collection = {
|
2023-07-25 16:19:19 +03:00
|
|
|
title: 'Test Collection with tag filter',
|
|
|
|
slug: 'tag-filter',
|
2023-07-18 14:50:18 +03:00
|
|
|
description: 'BACON!',
|
|
|
|
type: 'automatic',
|
|
|
|
filter: 'tags:[\'bacon\']'
|
|
|
|
};
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.post('/collections/')
|
|
|
|
.body({
|
|
|
|
collections: [collection]
|
|
|
|
})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('collections')
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
2023-07-25 16:19:19 +03:00
|
|
|
collections: [matchCollection]
|
2023-07-18 14:50:18 +03:00
|
|
|
});
|
|
|
|
|
2023-07-21 10:29:37 +03:00
|
|
|
await agent.get(`posts/?collection=${collection.slug}`)
|
2023-07-18 14:50:18 +03:00
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
2023-07-25 16:19:19 +03:00
|
|
|
posts: new Array(2).fill({
|
|
|
|
...matchPostShallowIncludes,
|
|
|
|
tags: new Array(2).fill(tagSnapshotMatcher)
|
|
|
|
})
|
2023-07-18 14:50:18 +03:00
|
|
|
});
|
|
|
|
});
|
2023-07-24 16:49:43 +03:00
|
|
|
|
|
|
|
it('Creates an automatic Collection with a tag filter, checking filter aliases', async function () {
|
|
|
|
const collection = {
|
|
|
|
title: 'Test Collection with tag filter alias',
|
|
|
|
slug: 'bacon-tag-expansion',
|
|
|
|
description: 'BACON!',
|
|
|
|
type: 'automatic',
|
|
|
|
filter: 'tag:[\'bacon\']'
|
|
|
|
};
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.post('/collections/')
|
|
|
|
.body({
|
|
|
|
collections: [collection]
|
|
|
|
})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('collections')
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
2023-07-25 16:19:19 +03:00
|
|
|
collections: [matchCollection]
|
2023-07-24 16:49:43 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await agent.get(`posts/?collection=${collection.slug}`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
2023-07-25 16:19:19 +03:00
|
|
|
posts: new Array(2).fill({
|
|
|
|
...matchPostShallowIncludes,
|
|
|
|
tags: new Array(2).fill(tagSnapshotMatcher)
|
|
|
|
})
|
2023-07-24 16:49:43 +03:00
|
|
|
});
|
|
|
|
});
|
2023-06-01 12:55:48 +03:00
|
|
|
});
|
2023-08-22 10:16:54 +03:00
|
|
|
|
|
|
|
describe('Collection Posts updates automatically', function () {
|
|
|
|
it('Updates collections when a Post is added/edited/deleted', async function () {
|
|
|
|
await agent
|
|
|
|
.get(`/collections/slug/featured/?include=count.posts`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [{
|
|
|
|
...matchCollection,
|
|
|
|
count: {
|
|
|
|
posts: 2
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
const postToAdd = {
|
|
|
|
title: 'Collection update test',
|
|
|
|
featured: false
|
|
|
|
};
|
|
|
|
|
|
|
|
const {body: {posts: [post]}} = await agent
|
|
|
|
.post('/posts/')
|
|
|
|
.body({
|
|
|
|
posts: [postToAdd]
|
|
|
|
})
|
|
|
|
.expectStatus(201);
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.get(`/collections/slug/featured/?include=count.posts`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [{
|
|
|
|
...matchCollection,
|
|
|
|
count: {
|
|
|
|
posts: 2
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.put(`/posts/${post.id}/`)
|
|
|
|
.body({
|
|
|
|
posts: [Object.assign({}, post, {featured: true})]
|
|
|
|
})
|
|
|
|
.expectStatus(200);
|
|
|
|
|
|
|
|
await DomainEvents.allSettled();
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.get(`/collections/slug/featured/?include=count.posts`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [{
|
|
|
|
...matchCollection,
|
|
|
|
count: {
|
|
|
|
posts: 3
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.delete(`/posts/${post.id}/`)
|
|
|
|
.expectStatus(204);
|
|
|
|
|
|
|
|
await DomainEvents.allSettled();
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.get(`/collections/slug/featured/?include=count.posts`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': anyContentVersion,
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
collections: [{
|
|
|
|
...matchCollection,
|
|
|
|
count: {
|
|
|
|
posts: 2
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-05-16 10:30:31 +03:00
|
|
|
});
|