aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/fixtures/index.ts1
-rw-r--r--tests/fixtures/wp-thematics.fixture.ts114
-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
10 files changed, 316 insertions, 2 deletions
diff --git a/tests/fixtures/index.ts b/tests/fixtures/index.ts
index 0c624c2..abe49be 100644
--- a/tests/fixtures/index.ts
+++ b/tests/fixtures/index.ts
@@ -1,2 +1,3 @@
export * from './wp-comments.fixture';
export * from './wp-posts.fixture';
+export * from './wp-thematics.fixture';
diff --git a/tests/fixtures/wp-thematics.fixture.ts b/tests/fixtures/wp-thematics.fixture.ts
new file mode 100644
index 0000000..ac9064a
--- /dev/null
+++ b/tests/fixtures/wp-thematics.fixture.ts
@@ -0,0 +1,114 @@
+import type { WPThematic } from '../../src/types';
+
+export const wpThematicsFixture: WPThematic[] = [
+ {
+ acfThematics: null,
+ contentParts: {
+ afterMore:
+ 'Iure sit itaque itaque exercitationem. Fuga quos mollitia dolorem est pariatur harum corrupti rerum soluta. Perferendis nemo quae accusamus omnis omnis facere quis ducimus autem. Debitis quam ut non. Rerum qui ut. Earum ex quis aspernatur aut qui ut.',
+ beforeMore:
+ 'Dolorem quaerat expedita id soluta sequi. Est quia alias unde voluptatem repudiandae voluptatibus reiciendis dolorum.',
+ },
+ databaseId: 1,
+ date: '2022-11-04',
+ featuredImage: null,
+ modified: '2022-11-05',
+ seo: {
+ metaDesc: 'In temporibus quis nihil veniam cum excepturi aliquam.',
+ title: 'aut veritatis molestias',
+ },
+ slug: '/veritatis-autem-voluptas',
+ title: 'veritatis autem voluptas',
+ },
+ {
+ acfThematics: null,
+ contentParts: {
+ afterMore:
+ 'Ut ut ullam est tenetur voluptatem aut facere. Cum necessitatibus dolor dolore. Magni rem qui odio laboriosam at sunt et sapiente. Earum incidunt enim eum voluptatum necessitatibus ipsa dolorum.',
+ beforeMore:
+ 'Et architecto libero aut ab ut alias nisi. Sed quibusdam sit expedita unde culpa et numquam unde. Hic amet eveniet sunt at exercitationem. Enim accusamus amet modi ea sunt perferendis. Numquam eaque maxime possimus. Et iure sequi facilis eum consequuntur rerum.',
+ },
+ databaseId: 2,
+ date: '2022-11-06',
+ featuredImage: {
+ node: {
+ altText: null,
+ mediaDetails: {
+ height: 480,
+ width: 640,
+ },
+ sourceUrl: 'https://picsum.photos/640/480',
+ title: null,
+ },
+ },
+ modified: '2022-11-06',
+ seo: {
+ metaDesc: 'Sed nulla nihil at dolores omnis repellendus qui sed.',
+ title: 'assumenda omnis placeat',
+ },
+ slug: '/aliquid-quia-eius',
+ title: 'aliquid quia eius',
+ },
+ {
+ acfThematics: {
+ postsInThematic: null,
+ },
+ databaseId: 3,
+ contentParts: {
+ afterMore:
+ 'Enim quis placeat cupiditate sit vel repellat. Architecto ex nam corrupti. Aspernatur sequi et reiciendis voluptate laudantium odit est consectetur. Aut harum fugit.',
+ beforeMore:
+ 'Et nemo impedit quia molestiae. Corrupti qui necessitatibus vitae aut doloribus enim possimus.',
+ },
+ date: '2022-11-07',
+ featuredImage: null,
+ modified: '2022-11-07',
+ seo: {
+ metaDesc:
+ 'Consequatur nisi dolorum fugiat mollitia aperiam ratione quibusdam.',
+ title: 'vel et velit',
+ },
+ slug: '/quasi-sint-nulla',
+ title: 'quasi sint nulla',
+ },
+ {
+ acfThematics: {
+ postsInThematic: [
+ {
+ acfPosts: null,
+ commentCount: 1,
+ contentParts: {
+ beforeMore:
+ 'Et porro distinctio dolores dolor enim fugit. Autem excepturi distinctio rerum mollitia dolor. Animi est consectetur omnis quia qui consequatur porro inventore. Quo voluptas nihil porro et nostrum velit autem commodi nulla. Qui temporibus dolorem totam.',
+ },
+ databaseId: 18,
+ date: '2021-10-10',
+ featuredImage: null,
+ info: {
+ wordsCount: 523,
+ },
+ modified: '2021-10-15',
+ slug: '/incidunt-cupiditate-in',
+ title: 'incidunt cupiditate in',
+ },
+ ],
+ },
+ contentParts: {
+ afterMore:
+ 'Cupiditate quidem quis debitis. Quae maiores tenetur cupiditate quibusdam est iure officia. Omnis enim ut accusantium nisi et recusandae.',
+ beforeMore:
+ 'Eum consequatur sint. Quibusdam illo quasi molestiae architecto excepturi. Quia optio adipisci voluptatem ex accusamus consequatur consequatur vel eveniet.',
+ },
+ databaseId: 4,
+ date: '2022-11-08',
+ featuredImage: null,
+ modified: '2022-11-10',
+ seo: {
+ metaDesc:
+ 'Recusandae et laboriosam repudiandae sit dignissimos accusantium.',
+ title: 'consectetur magni eum',
+ },
+ slug: '/numquam-commodi-velit',
+ title: 'numquam commodi velit',
+ },
+];
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