aboutsummaryrefslogtreecommitdiffstats
path: root/src/services/graphql/fetchers/posts/fetch-last-post-cursor.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/graphql/fetchers/posts/fetch-last-post-cursor.test.ts')
-rw-r--r--src/services/graphql/fetchers/posts/fetch-last-post-cursor.test.ts25
1 files changed, 25 insertions, 0 deletions
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.')
+ );
+ });
+});