aboutsummaryrefslogtreecommitdiffstats
path: root/tests/msw
diff options
context:
space:
mode:
Diffstat (limited to 'tests/msw')
-rw-r--r--tests/msw/handlers/index.ts7
-rw-r--r--tests/msw/handlers/thematics/index.ts11
-rw-r--r--tests/msw/handlers/thematics/thematic.handler.ts23
-rw-r--r--tests/msw/handlers/thematics/thematics-count.handler.ts45
-rw-r--r--tests/msw/handlers/thematics/thematics-list.handler.ts44
-rw-r--r--tests/msw/handlers/thematics/thematics-slugs.handler.ts26
-rw-r--r--tests/msw/schema/types/index.ts12
-rw-r--r--tests/msw/schema/types/thematic.types.ts35
8 files changed, 201 insertions, 2 deletions
diff --git a/tests/msw/handlers/index.ts b/tests/msw/handlers/index.ts
index 5f331e7..e42a0eb 100644
--- a/tests/msw/handlers/index.ts
+++ b/tests/msw/handlers/index.ts
@@ -1,4 +1,9 @@
import { commentsHandlers } from './comments';
import { postsHandlers } from './posts';
+import { thematicsHandlers } from './thematics';
-export const handlers = [...commentsHandlers, ...postsHandlers];
+export const handlers = [
+ ...commentsHandlers,
+ ...postsHandlers,
+ ...thematicsHandlers,
+];
diff --git a/tests/msw/handlers/thematics/index.ts b/tests/msw/handlers/thematics/index.ts
new file mode 100644
index 0000000..70ed3ca
--- /dev/null
+++ b/tests/msw/handlers/thematics/index.ts
@@ -0,0 +1,11 @@
+import { thematicHandler } from './thematic.handler';
+import { thematicsCountHandler } from './thematics-count.handler';
+import { thematicsListHandler } from './thematics-list.handler';
+import { thematicsSlugsHandler } from './thematics-slugs.handler';
+
+export const thematicsHandlers = [
+ thematicHandler,
+ thematicsCountHandler,
+ thematicsListHandler,
+ thematicsSlugsHandler,
+];
diff --git a/tests/msw/handlers/thematics/thematic.handler.ts b/tests/msw/handlers/thematics/thematic.handler.ts
new file mode 100644
index 0000000..1e7d129
--- /dev/null
+++ b/tests/msw/handlers/thematics/thematic.handler.ts
@@ -0,0 +1,23 @@
+import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
+import { HttpResponse, graphql } from 'msw';
+import type { ThematicResponse } from '../../../../src/services/graphql';
+import { wpThematicsFixture } from '../../../fixtures';
+import { schema } from '../../schema';
+
+export const thematicHandler = graphql.query<
+ ThematicResponse,
+ Record<'slug', string>
+>('Thematic', async ({ query, variables }) => {
+ const { data, errors } = (await executeGraphql({
+ schema,
+ source: query,
+ variableValues: variables,
+ rootValue: {
+ thematic: wpThematicsFixture.find(
+ (wpThematic) => wpThematic.slug === variables.slug
+ ),
+ },
+ })) as ExecutionResult<ThematicResponse>;
+
+ return HttpResponse.json({ data, errors });
+});
diff --git a/tests/msw/handlers/thematics/thematics-count.handler.ts b/tests/msw/handlers/thematics/thematics-count.handler.ts
new file mode 100644
index 0000000..4bcdf2d
--- /dev/null
+++ b/tests/msw/handlers/thematics/thematics-count.handler.ts
@@ -0,0 +1,45 @@
+import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
+import { HttpResponse, graphql } 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 { schema } from '../../schema';
+
+export const thematicsCountHandler = graphql.query<
+ ThematicsCountResponse,
+ GraphQLPostWhere
+>('ThematicsCount', async ({ query, variables }) => {
+ const pageParams = new URLSearchParams(window.location.search);
+ const isError = pageParams.get('error') === 'true';
+
+ if (isError) return HttpResponse.json({ data: { thematics: null } });
+
+ const { data, errors } = (await executeGraphql({
+ schema,
+ source: query,
+ variableValues: variables,
+ rootValue: {
+ thematics({ search, title }: typeof variables) {
+ const filteredThematicsByTitle = title
+ ? wpThematicsFixture.filter((thematic) =>
+ thematic.title.includes(title)
+ )
+ : wpThematicsFixture;
+ const filteredThematics = search
+ ? filteredThematicsByTitle.filter((thematic) =>
+ thematic.title.includes(search)
+ )
+ : filteredThematicsByTitle;
+
+ return getConnection({
+ after: null,
+ data: filteredThematics,
+ first: undefined,
+ });
+ },
+ },
+ })) as ExecutionResult<ThematicsCountResponse>;
+
+ return HttpResponse.json({ data, errors });
+});
diff --git a/tests/msw/handlers/thematics/thematics-list.handler.ts b/tests/msw/handlers/thematics/thematics-list.handler.ts
new file mode 100644
index 0000000..f206247
--- /dev/null
+++ b/tests/msw/handlers/thematics/thematics-list.handler.ts
@@ -0,0 +1,44 @@
+import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
+import { HttpResponse, graphql } from 'msw';
+import type {
+ FetchThematicsListInput,
+ ThematicsListResponse,
+} from '../../../../src/services/graphql';
+import { wpThematicsFixture } from '../../../fixtures';
+import { getConnection } from '../../../utils/graphql';
+import { schema } from '../../schema';
+
+export const thematicsListHandler = graphql.query<
+ ThematicsListResponse,
+ FetchThematicsListInput
+>('ThematicsList', async ({ query, variables }) => {
+ const pageParams = new URLSearchParams(window.location.search);
+ const isError = pageParams.get('error') === 'true';
+
+ if (isError) return HttpResponse.json({ data: { thematics: null } });
+
+ const { data, errors } = (await executeGraphql({
+ schema,
+ source: query,
+ variableValues: variables,
+ rootValue: {
+ thematics({ after, first, where }: typeof variables) {
+ const { search, title } = where ?? {};
+ const filteredThematicsByTitle = title
+ ? wpThematicsFixture.filter((thematic) =>
+ thematic.title.includes(title)
+ )
+ : wpThematicsFixture;
+ const filteredThematics = search
+ ? filteredThematicsByTitle.filter((thematic) =>
+ thematic.title.includes(search)
+ )
+ : filteredThematicsByTitle;
+
+ return getConnection({ after, data: filteredThematics, first });
+ },
+ },
+ })) as ExecutionResult<ThematicsListResponse>;
+
+ return HttpResponse.json({ data, errors });
+});
diff --git a/tests/msw/handlers/thematics/thematics-slugs.handler.ts b/tests/msw/handlers/thematics/thematics-slugs.handler.ts
new file mode 100644
index 0000000..3a71c8e
--- /dev/null
+++ b/tests/msw/handlers/thematics/thematics-slugs.handler.ts
@@ -0,0 +1,26 @@
+import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
+import { HttpResponse, graphql } from 'msw';
+import type { ThematicsSlugsResponse } from '../../../../src/services/graphql';
+import { wpThematicsFixture } from '../../../fixtures';
+import { schema } from '../../schema';
+
+export const thematicsSlugsHandler = graphql.query<
+ ThematicsSlugsResponse,
+ Record<'first', number>
+>('ThematicsSlugs', async ({ query, variables }) => {
+ const pageParams = new URLSearchParams(window.location.search);
+ const isError = pageParams.get('error') === 'true';
+
+ if (isError) return HttpResponse.json({ data: { thematics: null } });
+
+ const { data, errors } = (await executeGraphql({
+ schema,
+ source: query,
+ variableValues: variables,
+ rootValue: {
+ thematics: { nodes: wpThematicsFixture },
+ },
+ })) as ExecutionResult<ThematicsSlugsResponse>;
+
+ return HttpResponse.json({ data, errors });
+});
diff --git a/tests/msw/schema/types/index.ts b/tests/msw/schema/types/index.ts
index c34cacd..c570033 100644
--- a/tests/msw/schema/types/index.ts
+++ b/tests/msw/schema/types/index.ts
@@ -26,6 +26,18 @@ const rootQueryType = `type Query {
last: Int
where: RootQueryToPostConnectionWhereArgs
): RootQueryToPostConnection
+ thematic(
+ asPreview: Boolean
+ id: ID!
+ idType: ThematicIdType
+ ): Thematic
+ thematics(
+ after: String
+ before: String
+ first: Int
+ last: Int
+ where: RootQueryToThematicConnectionWhereArgs
+ ): RootQueryToThematicConnection
}`;
export const types = [
diff --git a/tests/msw/schema/types/thematic.types.ts b/tests/msw/schema/types/thematic.types.ts
index afa95c9..2af4f9a 100644
--- a/tests/msw/schema/types/thematic.types.ts
+++ b/tests/msw/schema/types/thematic.types.ts
@@ -1,4 +1,11 @@
-export const thematicTypes = `union Thematic_Acfthematics_PostsInThematic = Post
+export const thematicTypes = `enum ThematicIdType {
+ DATABASE_ID
+ ID
+ SLUG
+ URI
+}
+
+union Thematic_Acfthematics_PostsInThematic = Post
type Thematic_Acfthematics {
postsInThematic: [Thematic_Acfthematics_PostsInThematic]
@@ -15,6 +22,32 @@ type Thematic {
seo: PostTypeSEO
slug: String
title(format: PostObjectFieldFormatEnum): String
+}
+
+input RootQueryToThematicConnectionWhereArgs {
+ authorName: String
+ orderby: [PostObjectsConnectionOrderbyInput]
+ search: String
+ title: String
+}
+
+type RootQueryToThematicConnectionPageInfo {
+ endCursor: String
+ hasNextPage: Boolean!
+ hasPreviousPage: Boolean!
+ startCursor: String
+ total: Int
+}
+
+type RootQueryToThematicConnectionEdge {
+ cursor: String
+ node: Thematic!
+}
+
+type RootQueryToThematicConnection {
+ edges: [RootQueryToThematicConnectionEdge!]!
+ nodes: [Thematic!]!
+ pageInfo: RootQueryToThematicConnectionPageInfo!
}`;
// cSpell:ignore Acfthematics