This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
request all (if more than 1000) blog posts from Contentful
- Loading branch information
Tim Seckinger
committed
Nov 13, 2019
1 parent
52bb908
commit 7a3d444
Showing
16 changed files
with
78 additions
and
39 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/functions/blogMethods/__tests__/filter-posts-to-process.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/functions/blogMethods/__tests__/get-all-contentful-blog-post.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const GetAllContentfulBlogPosts = require('../get-all-contentful-blog-posts'); | ||
|
||
const posts = [...Array(2 ** 16).keys()].map(i => ({ slug: `post-${i}` })); | ||
|
||
const mockGetEntries = jest.fn(({ skip, limit }) => ({ | ||
skip, | ||
limit, | ||
total: posts.length, | ||
items: posts.slice(skip, skip + limit), | ||
})); | ||
const environment = { getEntries: mockGetEntries }; | ||
|
||
beforeEach(() => { | ||
mockGetEntries.mockClear(); | ||
}); | ||
|
||
it('requests blog posts', async () => { | ||
await GetAllContentfulBlogPosts(environment); | ||
mockGetEntries.mock.calls.map(([{ content_type }]) => { | ||
expect(content_type).toBe('blogPost'); | ||
}); | ||
}); | ||
|
||
it('requests until it has all entries and returns them', async () => { | ||
expect(await GetAllContentfulBlogPosts(environment)).toEqual(posts); | ||
}); | ||
|
||
it('does not exceed the contentful entry limit', async () => { | ||
await GetAllContentfulBlogPosts(environment); | ||
mockGetEntries.mock.calls.map(([{ limit }]) => { | ||
expect(limit).toBeLessThanOrEqual(1000); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/functions/blogMethods/__tests__/publish-to-contentful.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/functions/blogMethods/__tests__/transform-html-to-markdown.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/functions/blogMethods/__tests__/transform-meta-data.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/functions/blogMethods/custom-mdx/__tests__/add-frontmatter.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 6 additions & 14 deletions
20
src/functions/blogMethods/custom-mdx/__tests__/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/functions/blogMethods/custom-mdx/__tests__/transform-iframes.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/functions/blogMethods/custom-mdx/__tests__/transform-strings.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ests__/upload-image-to-contentful.test.js → ...ests__/upload-image-to-contentful.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/functions/blogMethods/get-all-contentful-blog-posts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const getAllBlogPosts = async environment => { | ||
let total = Number.POSITIVE_INFINITY; | ||
let items = []; | ||
|
||
while (items.length < total) { | ||
const { items: cmsPosts, total: cmsTotal } = await environment.getEntries({ | ||
content_type: 'blogPost', | ||
limit: 1000, | ||
skip: items.length, | ||
}); | ||
|
||
items.push(...cmsPosts); | ||
total = cmsTotal; | ||
} | ||
|
||
return items; | ||
}; | ||
|
||
module.exports = getAllBlogPosts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters