aboutsummaryrefslogtreecommitdiffstats
path: root/tests/msw/handlers/posts
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-12-06 18:20:54 +0100
committerArmand Philippot <git@armandphilippot.com>2023-12-07 19:12:11 +0100
commitb8eb008dd5927fb736e56699637f5f8549965eae (patch)
tree648274babea3d3d09ed3e0f5f1fef013f94158fb /tests/msw/handlers/posts
parent802285872a2c57e7a5e130f32a2b45497d7687f1 (diff)
refactor(hooks): replace useGithubApi with useGithubRepoMeta
* use GraphQL API instead of REST (the inconvenient however is that we now need an authorization token...) * move fetcher in services * add tests * mock response using MSW
Diffstat (limited to 'tests/msw/handlers/posts')
-rw-r--r--tests/msw/handlers/posts/last-post-cursor.handler.ts9
-rw-r--r--tests/msw/handlers/posts/post.handler.ts33
-rw-r--r--tests/msw/handlers/posts/posts-count.handler.ts9
-rw-r--r--tests/msw/handlers/posts/posts-list.handler.ts9
-rw-r--r--tests/msw/handlers/posts/posts-slugs.handler.ts9
-rw-r--r--tests/msw/handlers/posts/recent-posts.handler.ts9
6 files changed, 42 insertions, 36 deletions
diff --git a/tests/msw/handlers/posts/last-post-cursor.handler.ts b/tests/msw/handlers/posts/last-post-cursor.handler.ts
index 2f4b648..f5c58dc 100644
--- a/tests/msw/handlers/posts/last-post-cursor.handler.ts
+++ b/tests/msw/handlers/posts/last-post-cursor.handler.ts
@@ -1,11 +1,12 @@
-import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
-import { HttpResponse, graphql } from 'msw';
+import { type ExecutionResult, graphql } from 'graphql';
+import { HttpResponse } from 'msw';
import type { LastPostCursorResponse } from '../../../../src/services/graphql';
import { wpPostsFixture } from '../../../fixtures';
import { getConnection } from '../../../utils/graphql';
+import { wordpressAPI } from '../../instances';
import { schema } from '../../schema';
-export const lastPostCursorHandler = graphql.query<
+export const lastPostCursorHandler = wordpressAPI.query<
LastPostCursorResponse,
Record<'first', number>
>('LastPostCursor', async ({ query, variables }) => {
@@ -14,7 +15,7 @@ export const lastPostCursorHandler = graphql.query<
if (isError) return HttpResponse.json({ data: { posts: null } });
- const { data, errors } = (await executeGraphql({
+ const { data, errors } = (await graphql({
schema,
source: query,
variableValues: variables,
diff --git a/tests/msw/handlers/posts/post.handler.ts b/tests/msw/handlers/posts/post.handler.ts
index 4abdfed..72f7b95 100644
--- a/tests/msw/handlers/posts/post.handler.ts
+++ b/tests/msw/handlers/posts/post.handler.ts
@@ -1,21 +1,22 @@
-import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
-import { HttpResponse, graphql } from 'msw';
+import { type ExecutionResult, graphql } from 'graphql';
+import { HttpResponse } from 'msw';
import type { PostResponse } from '../../../../src/services/graphql';
import { wpPostsFixture } from '../../../fixtures';
+import { wordpressAPI } from '../../instances';
import { schema } from '../../schema';
-export const postHandler = graphql.query<PostResponse, Record<'slug', string>>(
- 'Post',
- async ({ query, variables }) => {
- const { data, errors } = (await executeGraphql({
- schema,
- source: query,
- variableValues: variables,
- rootValue: {
- post: wpPostsFixture.find((wpPost) => wpPost.slug === variables.slug),
- },
- })) as ExecutionResult<PostResponse>;
+export const postHandler = wordpressAPI.query<
+ PostResponse,
+ Record<'slug', string>
+>('Post', async ({ query, variables }) => {
+ const { data, errors } = (await graphql({
+ schema,
+ source: query,
+ variableValues: variables,
+ rootValue: {
+ post: wpPostsFixture.find((wpPost) => wpPost.slug === variables.slug),
+ },
+ })) as ExecutionResult<PostResponse>;
- return HttpResponse.json({ data, errors });
- }
-);
+ return HttpResponse.json({ data, errors });
+});
diff --git a/tests/msw/handlers/posts/posts-count.handler.ts b/tests/msw/handlers/posts/posts-count.handler.ts
index 95fa105..a4425a5 100644
--- a/tests/msw/handlers/posts/posts-count.handler.ts
+++ b/tests/msw/handlers/posts/posts-count.handler.ts
@@ -1,12 +1,13 @@
-import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
-import { HttpResponse, graphql } from 'msw';
+import { type ExecutionResult, graphql } from 'graphql';
+import { HttpResponse } from 'msw';
import type { PostsCountResponse } from '../../../../src/services/graphql';
import type { GraphQLPostWhere } from '../../../../src/types';
import { wpPostsFixture } from '../../../fixtures';
import { getConnection } from '../../../utils/graphql';
+import { wordpressAPI } from '../../instances';
import { schema } from '../../schema';
-export const postsCountHandler = graphql.query<
+export const postsCountHandler = wordpressAPI.query<
PostsCountResponse,
GraphQLPostWhere
>('PostsCount', async ({ query, variables }) => {
@@ -15,7 +16,7 @@ export const postsCountHandler = graphql.query<
if (isError) return HttpResponse.json({ data: { posts: null } });
- const { data, errors } = (await executeGraphql({
+ const { data, errors } = (await graphql({
schema,
source: query,
variableValues: variables,
diff --git a/tests/msw/handlers/posts/posts-list.handler.ts b/tests/msw/handlers/posts/posts-list.handler.ts
index 7f8daf6..e4992d1 100644
--- a/tests/msw/handlers/posts/posts-list.handler.ts
+++ b/tests/msw/handlers/posts/posts-list.handler.ts
@@ -1,14 +1,15 @@
-import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
-import { HttpResponse, graphql } from 'msw';
+import { type ExecutionResult, graphql } from 'graphql';
+import { HttpResponse } from 'msw';
import type {
FetchPostsListInput,
PostsListResponse,
} from '../../../../src/services/graphql';
import { wpPostsFixture } from '../../../fixtures';
import { getConnection } from '../../../utils/graphql';
+import { wordpressAPI } from '../../instances';
import { schema } from '../../schema';
-export const postsListHandler = graphql.query<
+export const postsListHandler = wordpressAPI.query<
PostsListResponse,
FetchPostsListInput
>('PostsList', async ({ query, variables }) => {
@@ -17,7 +18,7 @@ export const postsListHandler = graphql.query<
if (isError) return HttpResponse.json({ data: { posts: null } });
- const { data, errors } = (await executeGraphql({
+ const { data, errors } = (await graphql({
schema,
source: query,
variableValues: variables,
diff --git a/tests/msw/handlers/posts/posts-slugs.handler.ts b/tests/msw/handlers/posts/posts-slugs.handler.ts
index 9aadddb..69e300a 100644
--- a/tests/msw/handlers/posts/posts-slugs.handler.ts
+++ b/tests/msw/handlers/posts/posts-slugs.handler.ts
@@ -1,10 +1,11 @@
-import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
-import { HttpResponse, graphql } from 'msw';
+import { type ExecutionResult, graphql } from 'graphql';
+import { HttpResponse } from 'msw';
import type { PostsSlugsResponse } from '../../../../src/services/graphql';
import { wpPostsFixture } from '../../../fixtures';
+import { wordpressAPI } from '../../instances';
import { schema } from '../../schema';
-export const postsSlugsHandler = graphql.query<
+export const postsSlugsHandler = wordpressAPI.query<
PostsSlugsResponse,
Record<'first', number>
>('PostsSlugs', async ({ query, variables }) => {
@@ -13,7 +14,7 @@ export const postsSlugsHandler = graphql.query<
if (isError) return HttpResponse.json({ data: { posts: null } });
- const { data, errors } = (await executeGraphql({
+ const { data, errors } = (await graphql({
schema,
source: query,
variableValues: variables,
diff --git a/tests/msw/handlers/posts/recent-posts.handler.ts b/tests/msw/handlers/posts/recent-posts.handler.ts
index 34e0efb..eb89324 100644
--- a/tests/msw/handlers/posts/recent-posts.handler.ts
+++ b/tests/msw/handlers/posts/recent-posts.handler.ts
@@ -1,14 +1,15 @@
-import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
-import { HttpResponse, graphql } from 'msw';
+import { type ExecutionResult, graphql } from 'graphql';
+import { HttpResponse } from 'msw';
import type {
FetchPostsListInput,
RecentPostsResponse,
} from '../../../../src/services/graphql';
import { wpPostsFixture } from '../../../fixtures';
import { getConnection } from '../../../utils/graphql';
+import { wordpressAPI } from '../../instances';
import { schema } from '../../schema';
-export const recentPostsHandler = graphql.query<
+export const recentPostsHandler = wordpressAPI.query<
RecentPostsResponse,
FetchPostsListInput
>('RecentPosts', async ({ query, variables }) => {
@@ -17,7 +18,7 @@ export const recentPostsHandler = graphql.query<
if (isError) return HttpResponse.json({ data: { posts: null } });
- const { data, errors } = (await executeGraphql({
+ const { data, errors } = (await graphql({
schema,
source: query,
variableValues: variables,