From fb749e8befb2dcdc266c2e8b7ef7c9001947143a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 27 Nov 2023 19:40:40 +0100 Subject: test(services): add tests for posts fetchers --- .../fetchers/posts/fetch-last-post-cursor.test.ts | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/services/graphql/fetchers/posts/fetch-last-post-cursor.test.ts (limited to 'src/services/graphql/fetchers/posts/fetch-last-post-cursor.test.ts') diff --git a/src/services/graphql/fetchers/posts/fetch-last-post-cursor.test.ts b/src/services/graphql/fetchers/posts/fetch-last-post-cursor.test.ts new file mode 100644 index 0000000..4fe2f50 --- /dev/null +++ b/src/services/graphql/fetchers/posts/fetch-last-post-cursor.test.ts @@ -0,0 +1,25 @@ +import { afterEach, describe, expect, it } from '@jest/globals'; +import { fetchLastPostCursor } from './fetch-last-post-cursor'; + +describe('fetch-last-post-cursor', () => { + afterEach(() => { + window.history.replaceState({}, '', '/'); + }); + + it('returns the cursor of the last WordPress post using GraphQL', async () => { + const result = await fetchLastPostCursor(2); + + expect.assertions(1); + + expect(result).toBe('cursor2'); + }); + + it('rejects with an error when no posts are found', async () => { + window.history.replaceState({}, '', '/?error=true'); + expect.assertions(1); + + await expect(async () => fetchLastPostCursor(1)).rejects.toEqual( + new Error('Unable to find the cursor of the last post.') + ); + }); +}); -- cgit v1.2.3