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"]
|
"coming-soon": ["News"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"from": {
|
||||||
|
"model": "Collection",
|
||||||
|
"match": "slug",
|
||||||
|
"relation": "posts"
|
||||||
|
},
|
||||||
|
"to": {
|
||||||
|
"model": "Post",
|
||||||
|
"match": "slug"
|
||||||
|
},
|
||||||
|
"entries": {
|
||||||
|
"latest": ["coming-soon"]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"from": {
|
"from": {
|
||||||
"model": "User",
|
"model": "User",
|
||||||
|
|
|
@ -31,6 +31,7 @@ class PostsRepository {
|
||||||
const response = await this.browsePostsAPI({
|
const response = await this.browsePostsAPI({
|
||||||
options: {
|
options: {
|
||||||
filter: `(${filter})+type:post`,
|
filter: `(${filter})+type:post`,
|
||||||
|
status: 'all',
|
||||||
limit: 'all'
|
limit: 'all'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -44,7 +45,8 @@ class PostsRepository {
|
||||||
async getBulk(ids) {
|
async getBulk(ids) {
|
||||||
const response = await this.browsePostsAPI({
|
const response = await this.browsePostsAPI({
|
||||||
options: {
|
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_foot": null,
|
||||||
"codeinjection_head": null,
|
"codeinjection_head": null,
|
||||||
"collections": Array [
|
"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 {
|
Object {
|
||||||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.\\\\d\\{3\\}Z/,
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.\\\\d\\{3\\}Z/,
|
||||||
"description": null,
|
"description": null,
|
||||||
|
@ -1547,7 +1632,7 @@ exports[`Posts API Update Can add and remove collections 6: [headers] 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
"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",
|
"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-type": "application/json; charset=utf-8",
|
||||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
|
|
|
@ -15,6 +15,7 @@ const {
|
||||||
anyISODateTimeWithTZ,
|
anyISODateTimeWithTZ,
|
||||||
anyNumber,
|
anyNumber,
|
||||||
anyUuid,
|
anyUuid,
|
||||||
|
anyLocalURL,
|
||||||
anyString
|
anyString
|
||||||
} = matchers;
|
} = matchers;
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ const matchCollection = {
|
||||||
|
|
||||||
const matchCollectionPost = {
|
const matchCollectionPost = {
|
||||||
id: anyObjectId,
|
id: anyObjectId,
|
||||||
|
url: anyLocalURL,
|
||||||
created_at: anyISODateTimeWithTZ,
|
created_at: anyISODateTimeWithTZ,
|
||||||
updated_at: anyISODateTimeWithTZ,
|
updated_at: anyISODateTimeWithTZ,
|
||||||
published_at: anyISODateTimeWithTZ,
|
published_at: anyISODateTimeWithTZ,
|
||||||
|
@ -96,9 +98,8 @@ describe('Collections API', function () {
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
collections: [
|
collections: [
|
||||||
buildMatcher(11, {withSortOrder: true}),
|
buildMatcher(13, {withSortOrder: true}),
|
||||||
buildMatcher(2, {withSortOrder: true}),
|
buildMatcher(2, {withSortOrder: true}),
|
||||||
buildMatcher(0),
|
|
||||||
buildMatcher(0)
|
buildMatcher(0)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -108,23 +109,23 @@ describe('Collections API', function () {
|
||||||
describe('Browse Posts', function () {
|
describe('Browse Posts', function () {
|
||||||
it('Can browse Collections Posts', async function () {
|
it('Can browse Collections Posts', async function () {
|
||||||
const collections = await agent.get('/collections/');
|
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
|
await agent
|
||||||
.get(`/collections/${indexCollection.id}/posts/`)
|
.get(`/collections/${latestCollection.id}/posts/`)
|
||||||
.expectStatus(200)
|
.expectStatus(200)
|
||||||
.matchHeaderSnapshot({
|
.matchHeaderSnapshot({
|
||||||
'content-version': anyContentVersion,
|
'content-version': anyContentVersion,
|
||||||
etag: anyEtag
|
etag: anyEtag
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
collection_posts: Array(11).fill(matchCollectionPost)
|
collection_posts: Array(13).fill(matchCollectionPost)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can browse Collections Posts using paging parameters', async function () {
|
it('Can browse Collections Posts using paging parameters', async function () {
|
||||||
const collections = await agent.get('/collections/');
|
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
|
await agent
|
||||||
.get(`/collections/${indexCollection.id}/posts/?limit=2&page=2`)
|
.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 () {
|
it('Can browse Collections Posts using collection slug', async function () {
|
||||||
await agent
|
await agent
|
||||||
.get(`/collections/index/posts/`)
|
.get(`/collections/latest/posts/`)
|
||||||
.expectStatus(200)
|
.expectStatus(200)
|
||||||
.matchHeaderSnapshot({
|
.matchHeaderSnapshot({
|
||||||
'content-version': anyContentVersion,
|
'content-version': anyContentVersion,
|
||||||
etag: anyEtag
|
etag: anyEtag
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.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');
|
assert.equal(readResponse.body.collections[0].title, 'Test Collection to Read');
|
||||||
|
|
||||||
|
await agent
|
||||||
|
.delete(`/collections/${collectionId}/`)
|
||||||
|
.expectStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Edit', function () {
|
describe('Edit', function () {
|
||||||
|
@ -363,7 +368,7 @@ describe('Collections API', function () {
|
||||||
location: anyLocationFor('collections')
|
location: anyLocationFor('collections')
|
||||||
})
|
})
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
collections: [buildMatcher(7)]
|
collections: [buildMatcher(9)]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -473,6 +473,9 @@ describe('Posts API', function () {
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const collectionPostMatcher = {
|
||||||
|
id: anyObjectId
|
||||||
|
};
|
||||||
const collectionMatcher = {
|
const collectionMatcher = {
|
||||||
id: anyObjectId,
|
id: anyObjectId,
|
||||||
created_at: stringMatching(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/),
|
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
|
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}/`)
|
await agent.put(`/posts/${postResponse.id}/`)
|
||||||
.body({posts: [Object.assign({}, postResponse, {collections: [collectionToRemove.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]})]})
|
.body({posts: [Object.assign({}, postResponse, {collections: [collectionToAdd.id]})]})
|
||||||
.expectStatus(200)
|
.expectStatus(200)
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
posts: [Object.assign({}, matchPostShallowIncludes, {published_at: null}, {collections: [collectionMatcher]})]
|
posts: [
|
||||||
|
Object.assign({}, matchPostShallowIncludes, {published_at: null}, {collections: [
|
||||||
|
buildCollectionMatcher(18),
|
||||||
|
collectionMatcher
|
||||||
|
]}
|
||||||
|
)
|
||||||
|
]
|
||||||
})
|
})
|
||||||
.matchHeaderSnapshot({
|
.matchHeaderSnapshot({
|
||||||
'content-version': anyContentVersion,
|
'content-version': anyContentVersion,
|
||||||
|
|
|
@ -1123,6 +1123,28 @@
|
||||||
"sell": ["Getting Started"]
|
"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": {
|
"from": {
|
||||||
"model": "User",
|
"model": "User",
|
||||||
|
|
Loading…
Add table
Reference in a new issue