mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Added fixtures for collection posts
refs https://github.com/TryGhost/Arch/issues/25 - Adds collection_posts fixtures
This commit is contained in:
parent
b5d1245be1
commit
9bfb197a85
7 changed files with 404 additions and 97 deletions
|
@ -937,6 +937,20 @@
|
|||
"coming-soon": ["News"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": {
|
||||
"model": "Collection",
|
||||
"match": "slug",
|
||||
"relation": "posts"
|
||||
},
|
||||
"to": {
|
||||
"model": "Post",
|
||||
"match": "slug"
|
||||
},
|
||||
"entries": {
|
||||
"latest": ["coming-soon"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": {
|
||||
"model": "User",
|
||||
|
|
|
@ -31,6 +31,7 @@ class PostsRepository {
|
|||
const response = await this.browsePostsAPI({
|
||||
options: {
|
||||
filter: `(${filter})+type:post`,
|
||||
status: 'all',
|
||||
limit: 'all'
|
||||
}
|
||||
});
|
||||
|
@ -44,7 +45,8 @@ class PostsRepository {
|
|||
async getBulk(ids) {
|
||||
const response = await this.browsePostsAPI({
|
||||
options: {
|
||||
filter: `id:[${ids.join(',')}]+type:post`
|
||||
filter: `id:[${ids.join(',')}]+type:post`,
|
||||
status: 'all'
|
||||
}
|
||||
});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1440,6 +1440,91 @@ Object {
|
|||
"codeinjection_foot": null,
|
||||
"codeinjection_head": null,
|
||||
"collections": Array [
|
||||
Object {
|
||||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.\\\\d\\{3\\}Z/,
|
||||
"description": "Collection with all posts",
|
||||
"feature_image": null,
|
||||
"filter": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"posts": Array [
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 0,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 1,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 2,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 3,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 4,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 5,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 6,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 7,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 8,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 9,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 10,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 11,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 12,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 13,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 14,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 15,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 16,
|
||||
},
|
||||
Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"sort_order": 17,
|
||||
},
|
||||
],
|
||||
"slug": "latest",
|
||||
"title": "Latest",
|
||||
"type": "automatic",
|
||||
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.\\\\d\\{3\\}Z/,
|
||||
},
|
||||
Object {
|
||||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.\\\\d\\{3\\}Z/,
|
||||
"description": null,
|
||||
|
@ -1547,7 +1632,7 @@ exports[`Posts API Update Can add and remove collections 6: [headers] 1`] = `
|
|||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "4016",
|
||||
"content-length": "5159",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
|
|
|
@ -15,6 +15,7 @@ const {
|
|||
anyISODateTimeWithTZ,
|
||||
anyNumber,
|
||||
anyUuid,
|
||||
anyLocalURL,
|
||||
anyString
|
||||
} = matchers;
|
||||
|
||||
|
@ -26,6 +27,7 @@ const matchCollection = {
|
|||
|
||||
const matchCollectionPost = {
|
||||
id: anyObjectId,
|
||||
url: anyLocalURL,
|
||||
created_at: anyISODateTimeWithTZ,
|
||||
updated_at: anyISODateTimeWithTZ,
|
||||
published_at: anyISODateTimeWithTZ,
|
||||
|
@ -96,9 +98,8 @@ describe('Collections API', function () {
|
|||
})
|
||||
.matchBodySnapshot({
|
||||
collections: [
|
||||
buildMatcher(11, {withSortOrder: true}),
|
||||
buildMatcher(13, {withSortOrder: true}),
|
||||
buildMatcher(2, {withSortOrder: true}),
|
||||
buildMatcher(0),
|
||||
buildMatcher(0)
|
||||
]
|
||||
});
|
||||
|
@ -108,23 +109,23 @@ describe('Collections API', function () {
|
|||
describe('Browse Posts', function () {
|
||||
it('Can browse Collections Posts', async function () {
|
||||
const collections = await agent.get('/collections/');
|
||||
const indexCollection = collections.body.collections.find(c => c.slug === 'index');
|
||||
const latestCollection = collections.body.collections.find(c => c.slug === 'latest');
|
||||
|
||||
await agent
|
||||
.get(`/collections/${indexCollection.id}/posts/`)
|
||||
.get(`/collections/${latestCollection.id}/posts/`)
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
collection_posts: Array(11).fill(matchCollectionPost)
|
||||
collection_posts: Array(13).fill(matchCollectionPost)
|
||||
});
|
||||
});
|
||||
|
||||
it('Can browse Collections Posts using paging parameters', async function () {
|
||||
const collections = await agent.get('/collections/');
|
||||
const indexCollection = collections.body.collections.find(c => c.slug === 'index');
|
||||
const indexCollection = collections.body.collections.find(c => c.slug === 'latest');
|
||||
|
||||
await agent
|
||||
.get(`/collections/${indexCollection.id}/posts/?limit=2&page=2`)
|
||||
|
@ -140,14 +141,14 @@ describe('Collections API', function () {
|
|||
|
||||
it('Can browse Collections Posts using collection slug', async function () {
|
||||
await agent
|
||||
.get(`/collections/index/posts/`)
|
||||
.get(`/collections/latest/posts/`)
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
collection_posts: Array(11).fill(matchCollectionPost)
|
||||
collection_posts: Array(13).fill(matchCollectionPost)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -186,6 +187,10 @@ describe('Collections API', function () {
|
|||
});
|
||||
|
||||
assert.equal(readResponse.body.collections[0].title, 'Test Collection to Read');
|
||||
|
||||
await agent
|
||||
.delete(`/collections/${collectionId}/`)
|
||||
.expectStatus(204);
|
||||
});
|
||||
|
||||
describe('Edit', function () {
|
||||
|
@ -363,7 +368,7 @@ describe('Collections API', function () {
|
|||
location: anyLocationFor('collections')
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
collections: [buildMatcher(7)]
|
||||
collections: [buildMatcher(9)]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -473,6 +473,9 @@ describe('Posts API', function () {
|
|||
}]
|
||||
});
|
||||
|
||||
const collectionPostMatcher = {
|
||||
id: anyObjectId
|
||||
};
|
||||
const collectionMatcher = {
|
||||
id: anyObjectId,
|
||||
created_at: stringMatching(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/),
|
||||
|
@ -481,6 +484,14 @@ describe('Posts API', function () {
|
|||
id: anyObjectId
|
||||
}]
|
||||
};
|
||||
const buildCollectionMatcher = (postsCount) => {
|
||||
return {
|
||||
id: anyObjectId,
|
||||
created_at: stringMatching(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/),
|
||||
updated_at: stringMatching(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/),
|
||||
posts: Array(postsCount).fill(collectionPostMatcher)
|
||||
};
|
||||
};
|
||||
|
||||
await agent.put(`/posts/${postResponse.id}/`)
|
||||
.body({posts: [Object.assign({}, postResponse, {collections: [collectionToRemove.id]})]})
|
||||
|
@ -498,7 +509,13 @@ describe('Posts API', function () {
|
|||
.body({posts: [Object.assign({}, postResponse, {collections: [collectionToAdd.id]})]})
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
posts: [Object.assign({}, matchPostShallowIncludes, {published_at: null}, {collections: [collectionMatcher]})]
|
||||
posts: [
|
||||
Object.assign({}, matchPostShallowIncludes, {published_at: null}, {collections: [
|
||||
buildCollectionMatcher(18),
|
||||
collectionMatcher
|
||||
]}
|
||||
)
|
||||
]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
|
|
|
@ -1123,6 +1123,28 @@
|
|||
"sell": ["Getting Started"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": {
|
||||
"model": "Collection",
|
||||
"match": "slug",
|
||||
"relation": "posts"
|
||||
},
|
||||
"to": {
|
||||
"model": "Post",
|
||||
"match": "slug"
|
||||
},
|
||||
"entries": {
|
||||
"latest": {
|
||||
"integrations": "integrations",
|
||||
"grow": "grow",
|
||||
"sell": "sell",
|
||||
"portal": "portal",
|
||||
"write": "write",
|
||||
"design": "design",
|
||||
"welcome": "welcome"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": {
|
||||
"model": "User",
|
||||
|
|
Loading…
Add table
Reference in a new issue