mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Removed posts
from Collections API
The correct mechanism for fetching posts from a collection is via the Posts API. This removes all functionality of getting posts from the Collections API. Co-authored-by: Naz <hi@nazavo.com>
This commit is contained in:
parent
adc3f8e8ee
commit
63ab254e33
3 changed files with 519 additions and 623 deletions
|
@ -6,23 +6,10 @@
|
||||||
*/
|
*/
|
||||||
const mapper = (collection) => {
|
const mapper = (collection) => {
|
||||||
let json;
|
let json;
|
||||||
let posts;
|
|
||||||
if (collection.toJSON) {
|
if (collection.toJSON) {
|
||||||
json = collection.toJSON();
|
json = collection.toJSON();
|
||||||
posts = json.posts.map((postId, index) => {
|
|
||||||
return {
|
|
||||||
id: postId,
|
|
||||||
sort_order: index
|
|
||||||
};
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
json = collection;
|
json = collection;
|
||||||
posts = json.posts.map((post) => {
|
|
||||||
return {
|
|
||||||
id: post.id,
|
|
||||||
sort_order: post.sort_order
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const serialized = {
|
const serialized = {
|
||||||
|
@ -34,8 +21,7 @@ const mapper = (collection) => {
|
||||||
filter: json.filter,
|
filter: json.filter,
|
||||||
feature_image: json.feature_image || json.featureImage || null,
|
feature_image: json.feature_image || json.featureImage || null,
|
||||||
created_at: (json.created_at || json.createdAt).toISOString().replace(/\d{3}Z$/, '000Z'),
|
created_at: (json.created_at || json.createdAt).toISOString().replace(/\d{3}Z$/, '000Z'),
|
||||||
updated_at: (json.updated_at || json.updatedAt).toISOString().replace(/\d{3}Z$/, '000Z'),
|
updated_at: (json.updated_at || json.updatedAt).toISOString().replace(/\d{3}Z$/, '000Z')
|
||||||
posts
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return serialized;
|
return serialized;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -12,7 +12,6 @@ const {
|
||||||
anyLocationFor,
|
anyLocationFor,
|
||||||
anyObjectId,
|
anyObjectId,
|
||||||
anyISODateTime,
|
anyISODateTime,
|
||||||
anyNumber,
|
|
||||||
anyString,
|
anyString,
|
||||||
anyUuid,
|
anyUuid,
|
||||||
anyArray,
|
anyArray,
|
||||||
|
@ -25,12 +24,6 @@ const matchCollection = {
|
||||||
updated_at: anyISODateTime
|
updated_at: anyISODateTime
|
||||||
};
|
};
|
||||||
|
|
||||||
const tierSnapshot = {
|
|
||||||
id: anyObjectId,
|
|
||||||
created_at: anyISODateTime,
|
|
||||||
updated_at: anyISODateTime
|
|
||||||
};
|
|
||||||
|
|
||||||
const tagSnapshotMatcher = {
|
const tagSnapshotMatcher = {
|
||||||
id: anyObjectId,
|
id: anyObjectId,
|
||||||
created_at: anyISODateTime,
|
created_at: anyISODateTime,
|
||||||
|
@ -44,32 +37,15 @@ const matchPostShallowIncludes = {
|
||||||
url: anyString,
|
url: anyString,
|
||||||
authors: anyArray,
|
authors: anyArray,
|
||||||
primary_author: anyObject,
|
primary_author: anyObject,
|
||||||
tags: Array(2).fill(tagSnapshotMatcher),
|
tags: anyArray,
|
||||||
primary_tag: anyObject,
|
primary_tag: anyObject,
|
||||||
tiers: Array(2).fill(tierSnapshot),
|
tiers: anyArray,
|
||||||
created_at: anyISODateTime,
|
created_at: anyISODateTime,
|
||||||
updated_at: anyISODateTime,
|
updated_at: anyISODateTime,
|
||||||
published_at: anyISODateTime,
|
published_at: anyISODateTime,
|
||||||
post_revisions: anyArray
|
post_revisions: anyArray
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {number} postCount
|
|
||||||
*/
|
|
||||||
const buildMatcher = (postCount, opts = {}) => {
|
|
||||||
let obj = {
|
|
||||||
id: anyObjectId
|
|
||||||
};
|
|
||||||
if (opts.withSortOrder) {
|
|
||||||
obj.sort_order = anyNumber;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...matchCollection,
|
|
||||||
posts: Array(postCount).fill(obj)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('Collections API', function () {
|
describe('Collections API', function () {
|
||||||
let agent;
|
let agent;
|
||||||
|
|
||||||
|
@ -117,9 +93,9 @@ describe('Collections API', function () {
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
collections: [
|
collections: [
|
||||||
buildMatcher(13, {withSortOrder: true}),
|
matchCollection,
|
||||||
buildMatcher(2, {withSortOrder: true}),
|
matchCollection,
|
||||||
buildMatcher(0)
|
matchCollection
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -312,6 +288,7 @@ describe('Collections API', function () {
|
||||||
it('Creates an automatic Collection with a featured filter', async function () {
|
it('Creates an automatic Collection with a featured filter', async function () {
|
||||||
const collection = {
|
const collection = {
|
||||||
title: 'Test Featured Collection',
|
title: 'Test Featured Collection',
|
||||||
|
slug: 'featured-filter',
|
||||||
description: 'Test Collection Description',
|
description: 'Test Collection Description',
|
||||||
type: 'automatic',
|
type: 'automatic',
|
||||||
filter: 'featured:true'
|
filter: 'featured:true'
|
||||||
|
@ -329,13 +306,24 @@ describe('Collections API', function () {
|
||||||
location: anyLocationFor('collections')
|
location: anyLocationFor('collections')
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
collections: [buildMatcher(2)]
|
collections: [matchCollection]
|
||||||
|
});
|
||||||
|
|
||||||
|
await agent.get(`posts/?collection=${collection.slug}`)
|
||||||
|
.expectStatus(200)
|
||||||
|
.matchHeaderSnapshot({
|
||||||
|
'content-version': anyContentVersion,
|
||||||
|
etag: anyEtag
|
||||||
|
})
|
||||||
|
.matchBodySnapshot({
|
||||||
|
posts: new Array(2).fill(matchPostShallowIncludes)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Creates an automatic Collection with a published_at filter', async function () {
|
it('Creates an automatic Collection with a published_at filter', async function () {
|
||||||
const collection = {
|
const collection = {
|
||||||
title: 'Test Collection with published_at filter',
|
title: 'Test Collection with published_at filter',
|
||||||
|
slug: 'published-at-filter',
|
||||||
description: 'Test Collection Description with published_at filter',
|
description: 'Test Collection Description with published_at filter',
|
||||||
type: 'automatic',
|
type: 'automatic',
|
||||||
filter: 'published_at:>=2022-05-25'
|
filter: 'published_at:>=2022-05-25'
|
||||||
|
@ -353,14 +341,24 @@ describe('Collections API', function () {
|
||||||
location: anyLocationFor('collections')
|
location: anyLocationFor('collections')
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
collections: [buildMatcher(9)]
|
collections: [matchCollection]
|
||||||
|
});
|
||||||
|
|
||||||
|
await agent.get(`posts/?collection=${collection.slug}`)
|
||||||
|
.expectStatus(200)
|
||||||
|
.matchHeaderSnapshot({
|
||||||
|
'content-version': anyContentVersion,
|
||||||
|
etag: anyEtag
|
||||||
|
})
|
||||||
|
.matchBodySnapshot({
|
||||||
|
posts: new Array(7).fill(matchPostShallowIncludes)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Creates an automatic Collection with a tags filter', async function () {
|
it('Creates an automatic Collection with a tags filter', async function () {
|
||||||
const collection = {
|
const collection = {
|
||||||
title: 'Test Collection with tags filter',
|
title: 'Test Collection with tag filter',
|
||||||
slug: 'bacon',
|
slug: 'tag-filter',
|
||||||
description: 'BACON!',
|
description: 'BACON!',
|
||||||
type: 'automatic',
|
type: 'automatic',
|
||||||
filter: 'tags:[\'bacon\']'
|
filter: 'tags:[\'bacon\']'
|
||||||
|
@ -378,7 +376,7 @@ describe('Collections API', function () {
|
||||||
location: anyLocationFor('collections')
|
location: anyLocationFor('collections')
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
collections: [buildMatcher(2)]
|
collections: [matchCollection]
|
||||||
});
|
});
|
||||||
|
|
||||||
await agent.get(`posts/?collection=${collection.slug}`)
|
await agent.get(`posts/?collection=${collection.slug}`)
|
||||||
|
@ -388,7 +386,10 @@ describe('Collections API', function () {
|
||||||
etag: anyEtag
|
etag: anyEtag
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
posts: new Array(2).fill(matchPostShallowIncludes)
|
posts: new Array(2).fill({
|
||||||
|
...matchPostShallowIncludes,
|
||||||
|
tags: new Array(2).fill(tagSnapshotMatcher)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -413,7 +414,7 @@ describe('Collections API', function () {
|
||||||
location: anyLocationFor('collections')
|
location: anyLocationFor('collections')
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
collections: [buildMatcher(2)]
|
collections: [matchCollection]
|
||||||
});
|
});
|
||||||
|
|
||||||
await agent.get(`posts/?collection=${collection.slug}`)
|
await agent.get(`posts/?collection=${collection.slug}`)
|
||||||
|
@ -423,7 +424,10 @@ describe('Collections API', function () {
|
||||||
etag: anyEtag
|
etag: anyEtag
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
posts: new Array(2).fill(matchPostShallowIncludes)
|
posts: new Array(2).fill({
|
||||||
|
...matchPostShallowIncludes,
|
||||||
|
tags: new Array(2).fill(tagSnapshotMatcher)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue