diff options
Diffstat (limited to 'tests/msw/handlers')
18 files changed, 118 insertions, 66 deletions
diff --git a/tests/msw/handlers/comments/comments-list.handler.ts b/tests/msw/handlers/comments/comments-list.handler.ts index e815a0e..ad760fc 100644 --- a/tests/msw/handlers/comments/comments-list.handler.ts +++ b/tests/msw/handlers/comments/comments-list.handler.ts @@ -1,13 +1,14 @@ -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 { FetchCommentsListInput, CommentsListResponse, } from '../../../../src/services/graphql'; import { wpCommentsFixture } from '../../../fixtures'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const commentsListHandler = graphql.query< +export const commentsListHandler = wordpressAPI.query< CommentsListResponse, FetchCommentsListInput >('CommentsList', async ({ query, variables }) => { @@ -16,7 +17,7 @@ export const commentsListHandler = graphql.query< if (isError) return HttpResponse.json({ data: { comments: null } }); - const { data, errors } = (await executeGraphql({ + const { data, errors } = (await graphql({ schema, source: query, variableValues: variables, diff --git a/tests/msw/handlers/index.ts b/tests/msw/handlers/index.ts index 85a2300..bfdeb95 100644 --- a/tests/msw/handlers/index.ts +++ b/tests/msw/handlers/index.ts @@ -1,11 +1,13 @@ import { commentsHandlers } from './comments'; import { postsHandlers } from './posts'; +import { repositoriesHandlers } from './repositories'; import { thematicsHandlers } from './thematics'; import { topicsHandlers } from './topics'; export const handlers = [ ...commentsHandlers, ...postsHandlers, + ...repositoriesHandlers, ...thematicsHandlers, ...topicsHandlers, ]; 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, diff --git a/tests/msw/handlers/repositories/index.ts b/tests/msw/handlers/repositories/index.ts new file mode 100644 index 0000000..b29a41f --- /dev/null +++ b/tests/msw/handlers/repositories/index.ts @@ -0,0 +1,3 @@ +import { repositoryHandler } from './repository.handler'; + +export const repositoriesHandlers = [repositoryHandler]; diff --git a/tests/msw/handlers/repositories/repository.handler.ts b/tests/msw/handlers/repositories/repository.handler.ts new file mode 100644 index 0000000..2c459c1 --- /dev/null +++ b/tests/msw/handlers/repositories/repository.handler.ts @@ -0,0 +1,32 @@ +import { type ExecutionResult, graphql } from 'graphql'; +import { HttpResponse } from 'msw'; +import type { + FetchGithubRepoMetaInput, + GithubRepositoryResponse, +} from '../../../../src/services/github'; +import { githubRepos } from '../../../fixtures'; +import { githubAPI } from '../../instances'; +import { githubSchema } from '../../schema'; + +export const repositoryHandler = githubAPI.query< + GithubRepositoryResponse, + FetchGithubRepoMetaInput +>('GithubRepository', async ({ query, variables }) => { + const pageParams = new URLSearchParams(window.location.search); + const isError = pageParams.get('error') === 'true'; + + if (isError) return HttpResponse.json({ data: { repository: null } }); + + const { data, errors } = (await graphql({ + schema: githubSchema, + source: query, + variableValues: variables, + rootValue: { + repository: githubRepos.find( + (repo) => repo.owner === variables.owner && repo.name === variables.name + ), + }, + })) as ExecutionResult<GithubRepositoryResponse>; + + return HttpResponse.json({ data, errors }); +}); diff --git a/tests/msw/handlers/thematics/thematic.handler.ts b/tests/msw/handlers/thematics/thematic.handler.ts index 1e7d129..ad82ea6 100644 --- a/tests/msw/handlers/thematics/thematic.handler.ts +++ b/tests/msw/handlers/thematics/thematic.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 { ThematicResponse } from '../../../../src/services/graphql'; import { wpThematicsFixture } from '../../../fixtures'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const thematicHandler = graphql.query< +export const thematicHandler = wordpressAPI.query< ThematicResponse, Record<'slug', string> >('Thematic', async ({ query, variables }) => { - const { data, errors } = (await executeGraphql({ + const { data, errors } = (await graphql({ schema, source: query, variableValues: variables, diff --git a/tests/msw/handlers/thematics/thematics-count.handler.ts b/tests/msw/handlers/thematics/thematics-count.handler.ts index 4bcdf2d..8a1f12e 100644 --- a/tests/msw/handlers/thematics/thematics-count.handler.ts +++ b/tests/msw/handlers/thematics/thematics-count.handler.ts @@ -1,12 +1,13 @@ import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; -import { HttpResponse, graphql } from 'msw'; +import { HttpResponse } from 'msw'; import type { ThematicsCountResponse } from '../../../../src/services/graphql'; import type { GraphQLPostWhere } from '../../../../src/types'; import { wpThematicsFixture } from '../../../fixtures'; import { getConnection } from '../../../utils/graphql'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const thematicsCountHandler = graphql.query< +export const thematicsCountHandler = wordpressAPI.query< ThematicsCountResponse, GraphQLPostWhere >('ThematicsCount', async ({ query, variables }) => { diff --git a/tests/msw/handlers/thematics/thematics-list.handler.ts b/tests/msw/handlers/thematics/thematics-list.handler.ts index 7afec4c..790fa5a 100644 --- a/tests/msw/handlers/thematics/thematics-list.handler.ts +++ b/tests/msw/handlers/thematics/thematics-list.handler.ts @@ -1,14 +1,15 @@ import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; -import { HttpResponse, graphql } from 'msw'; +import { HttpResponse } from 'msw'; import type { FetchThematicsListInput, ThematicsListResponse, } from '../../../../src/services/graphql'; import { wpThematicsFixture } from '../../../fixtures'; import { getConnection } from '../../../utils/graphql'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const thematicsListHandler = graphql.query< +export const thematicsListHandler = wordpressAPI.query< ThematicsListResponse, FetchThematicsListInput >('ThematicsList', async ({ query, variables }) => { diff --git a/tests/msw/handlers/thematics/thematics-slugs.handler.ts b/tests/msw/handlers/thematics/thematics-slugs.handler.ts index 3a71c8e..77bbeda 100644 --- a/tests/msw/handlers/thematics/thematics-slugs.handler.ts +++ b/tests/msw/handlers/thematics/thematics-slugs.handler.ts @@ -1,10 +1,11 @@ import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; -import { HttpResponse, graphql } from 'msw'; +import { HttpResponse } from 'msw'; import type { ThematicsSlugsResponse } from '../../../../src/services/graphql'; import { wpThematicsFixture } from '../../../fixtures'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const thematicsSlugsHandler = graphql.query< +export const thematicsSlugsHandler = wordpressAPI.query< ThematicsSlugsResponse, Record<'first', number> >('ThematicsSlugs', async ({ query, variables }) => { diff --git a/tests/msw/handlers/topics/topic.handler.ts b/tests/msw/handlers/topics/topic.handler.ts index 5df00ea..1cb565b 100644 --- a/tests/msw/handlers/topics/topic.handler.ts +++ b/tests/msw/handlers/topics/topic.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 { TopicResponse } from '../../../../src/services/graphql'; import { wpTopicsFixture } from '../../../fixtures'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const topicHandler = graphql.query< +export const topicHandler = wordpressAPI.query< TopicResponse, Record<'slug', string> >('Topic', async ({ query, variables }) => { - const { data, errors } = (await executeGraphql({ + const { data, errors } = (await graphql({ schema, source: query, variableValues: variables, diff --git a/tests/msw/handlers/topics/topics-count.handler.ts b/tests/msw/handlers/topics/topics-count.handler.ts index 7e3dab9..0a48d06 100644 --- a/tests/msw/handlers/topics/topics-count.handler.ts +++ b/tests/msw/handlers/topics/topics-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 { TopicsCountResponse } from '../../../../src/services/graphql'; import type { GraphQLPostWhere } from '../../../../src/types'; import { wpTopicsFixture } from '../../../fixtures'; import { getConnection } from '../../../utils/graphql'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const topicsCountHandler = graphql.query< +export const topicsCountHandler = wordpressAPI.query< TopicsCountResponse, GraphQLPostWhere >('TopicsCount', async ({ query, variables }) => { @@ -15,7 +16,7 @@ export const topicsCountHandler = graphql.query< if (isError) return HttpResponse.json({ data: { topics: null } }); - const { data, errors } = (await executeGraphql({ + const { data, errors } = (await graphql({ schema, source: query, variableValues: variables, diff --git a/tests/msw/handlers/topics/topics-list.handler.ts b/tests/msw/handlers/topics/topics-list.handler.ts index 4b09c5a..86a8dba 100644 --- a/tests/msw/handlers/topics/topics-list.handler.ts +++ b/tests/msw/handlers/topics/topics-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 { FetchTopicsListInput, TopicsListResponse, } from '../../../../src/services/graphql'; import { wpTopicsFixture } from '../../../fixtures'; import { getConnection } from '../../../utils/graphql'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const topicsListHandler = graphql.query< +export const topicsListHandler = wordpressAPI.query< TopicsListResponse, FetchTopicsListInput >('TopicsList', async ({ query, variables }) => { @@ -17,7 +18,7 @@ export const topicsListHandler = graphql.query< if (isError) return HttpResponse.json({ data: { topics: null } }); - const { data, errors } = (await executeGraphql({ + const { data, errors } = (await graphql({ schema, source: query, variableValues: variables, diff --git a/tests/msw/handlers/topics/topics-slugs.handler.ts b/tests/msw/handlers/topics/topics-slugs.handler.ts index 960e411..779a384 100644 --- a/tests/msw/handlers/topics/topics-slugs.handler.ts +++ b/tests/msw/handlers/topics/topics-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 { TopicsSlugsResponse } from '../../../../src/services/graphql'; import { wpTopicsFixture } from '../../../fixtures'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const topicsSlugsHandler = graphql.query< +export const topicsSlugsHandler = wordpressAPI.query< TopicsSlugsResponse, Record<'first', number> >('TopicsSlugs', async ({ query, variables }) => { @@ -13,7 +14,7 @@ export const topicsSlugsHandler = graphql.query< if (isError) return HttpResponse.json({ data: { topics: null } }); - const { data, errors } = (await executeGraphql({ + const { data, errors } = (await graphql({ schema, source: query, variableValues: variables, |
