diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/fixtures/index.ts | 1 | ||||
| -rw-r--r-- | tests/fixtures/wp-topics.fixture.ts | 118 | ||||
| -rw-r--r-- | tests/msw/handlers/index.ts | 2 | ||||
| -rw-r--r-- | tests/msw/handlers/topics/index.ts | 11 | ||||
| -rw-r--r-- | tests/msw/handlers/topics/topic.handler.ts | 21 | ||||
| -rw-r--r-- | tests/msw/handlers/topics/topics-count.handler.ts | 43 | ||||
| -rw-r--r-- | tests/msw/handlers/topics/topics-list.handler.ts | 42 | ||||
| -rw-r--r-- | tests/msw/handlers/topics/topics-slugs.handler.ts | 26 | ||||
| -rw-r--r-- | tests/msw/schema/types/index.ts | 12 | ||||
| -rw-r--r-- | tests/msw/schema/types/topic.types.ts | 35 |
10 files changed, 310 insertions, 1 deletions
diff --git a/tests/fixtures/index.ts b/tests/fixtures/index.ts index abe49be..2ae0185 100644 --- a/tests/fixtures/index.ts +++ b/tests/fixtures/index.ts @@ -1,3 +1,4 @@ export * from './wp-comments.fixture'; export * from './wp-posts.fixture'; export * from './wp-thematics.fixture'; +export * from './wp-topics.fixture'; diff --git a/tests/fixtures/wp-topics.fixture.ts b/tests/fixtures/wp-topics.fixture.ts new file mode 100644 index 0000000..d790dea --- /dev/null +++ b/tests/fixtures/wp-topics.fixture.ts @@ -0,0 +1,118 @@ +import type { WPTopic } from '../../src/types'; + +export const wpTopicsFixture: WPTopic[] = [ + { + acfTopics: null, + contentParts: { + afterMore: + 'Ut nemo quia repellendus aut aliquid voluptatum rerum incidunt in. Voluptatem modi quia enim est molestiae at facere non. Sunt dolores debitis ipsam praesentium et unde quas veritatis. Mollitia illo corporis aut quia distinctio.', + beforeMore: + 'Veniam cumque ut nulla. Aspernatur quos similique nesciunt. Dignissimos maxime ex iure non ut nemo ea ducimus. Vero sit sed quis. Et sed facilis quia possimus animi. Debitis illum et et dolores minus.', + }, + databaseId: 1, + date: '2022-10-03', + featuredImage: null, + modified: '2022-10-04', + seo: { + metaDesc: 'Et magnam id dicta iste molestiae illum officia provident.', + title: 'est dolores tempore', + }, + slug: '/eveniet-ut-quis', + title: 'eveniet ut quis', + }, + { + acfTopics: { + officialWebsite: 'https://example.test', + postsInTopic: null, + }, + contentParts: { + afterMore: + 'Est odit et quia qui vero nemo necessitatibus. Culpa molestias illo earum aut inventore amet aut numquam. Nulla qui delectus aperiam ipsa voluptates expedita nihil. Sit explicabo sunt exercitationem nesciunt quae.', + beforeMore: + 'Ut doloremque nisi facilis officiis officiis et id ipsam. Aut ex quaerat autem a libero aut suscipit illum. Quasi quia commodi reiciendis. Voluptas ratione totam qui possimus fuga.', + }, + databaseId: 2, + date: '2022-10-06', + featuredImage: { + node: { + altText: null, + mediaDetails: { + height: 480, + width: 640, + }, + sourceUrl: 'https://picsum.photos/640/480', + title: null, + }, + }, + modified: '2022-10-06', + seo: { + metaDesc: + 'Consequuntur aut excepturi dicta et qui quasi enim voluptas cum.', + title: 'aliquid consectetur corporis', + }, + slug: '/nisi-ut-facere', + title: 'nisi ut facere', + }, + { + acfTopics: { + officialWebsite: null, + postsInTopic: null, + }, + databaseId: 3, + contentParts: { + afterMore: + 'Quod distinctio soluta quam repudiandae assumenda numquam quos. Aliquid sint cupiditate voluptates cum fugiat natus ut. Aliquid totam beatae eveniet dicta itaque et asperiores quis. Sapiente impedit maiores illum. Totam magnam unde dolor eaque.', + beforeMore: + 'Quibusdam pariatur hic voluptas sit ipsam sed. Quisquam nisi est. Optio eaque sunt omnis eos repellat nostrum. Voluptatem eaque vero neque maxime consequatur sunt eligendi suscipit molestias.', + }, + date: '2022-08-27', + featuredImage: null, + modified: '2022-08-30', + seo: { + metaDesc: 'Sed impedit quisquam voluptate voluptatem consequuntur.', + title: 'porro autem sunt', + }, + slug: '/iusto-non-consectetur', + title: 'iusto non consectetur', + }, + { + acfTopics: { + officialWebsite: null, + postsInTopic: [ + { + acfPosts: null, + commentCount: 4, + contentParts: { + beforeMore: + 'Incidunt et sit ea nostrum rerum consectetur quia. Et quia quibusdam dolor sit itaque voluptas.', + }, + databaseId: 15, + date: '2021-09-10', + featuredImage: null, + info: { + wordsCount: 468, + }, + modified: '2021-09-15', + slug: '/possimus-temporibus-magni', + title: 'possimus temporibus magni', + }, + ], + }, + contentParts: { + afterMore: + 'Eius vel neque est minus eius nihil est aperiam dolorem. Vel vel vero esse dolore sapiente quia et. Iusto et ratione est quia eveniet porro tenetur. Adipisci dicta ut delectus dolor sit tenetur molestias.', + beforeMore: + 'Molestias et veniam impedit et ut sunt aliquid id. Molestiae debitis ipsa reprehenderit aperiam totam quia. Accusamus iste sit corrupti voluptatibus consequatur odio error. Asperiores ipsa error nulla perspiciatis accusantium inventore.', + }, + databaseId: 4, + date: '2022-10-07', + featuredImage: null, + modified: '2022-10-10', + seo: { + metaDesc: 'Quaerat non ex inventore officiis amet.', + title: 'in alias ipsa', + }, + slug: '/non-repellendus-ipsam', + title: 'non repellendus ipsam', + }, +]; diff --git a/tests/msw/handlers/index.ts b/tests/msw/handlers/index.ts index e42a0eb..85a2300 100644 --- a/tests/msw/handlers/index.ts +++ b/tests/msw/handlers/index.ts @@ -1,9 +1,11 @@ import { commentsHandlers } from './comments'; import { postsHandlers } from './posts'; import { thematicsHandlers } from './thematics'; +import { topicsHandlers } from './topics'; export const handlers = [ ...commentsHandlers, ...postsHandlers, ...thematicsHandlers, + ...topicsHandlers, ]; diff --git a/tests/msw/handlers/topics/index.ts b/tests/msw/handlers/topics/index.ts new file mode 100644 index 0000000..e29694b --- /dev/null +++ b/tests/msw/handlers/topics/index.ts @@ -0,0 +1,11 @@ +import { topicHandler } from './topic.handler'; +import { topicsCountHandler } from './topics-count.handler'; +import { topicsListHandler } from './topics-list.handler'; +import { topicsSlugsHandler } from './topics-slugs.handler'; + +export const topicsHandlers = [ + topicHandler, + topicsCountHandler, + topicsListHandler, + topicsSlugsHandler, +]; diff --git a/tests/msw/handlers/topics/topic.handler.ts b/tests/msw/handlers/topics/topic.handler.ts new file mode 100644 index 0000000..5df00ea --- /dev/null +++ b/tests/msw/handlers/topics/topic.handler.ts @@ -0,0 +1,21 @@ +import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; +import { HttpResponse, graphql } from 'msw'; +import type { TopicResponse } from '../../../../src/services/graphql'; +import { wpTopicsFixture } from '../../../fixtures'; +import { schema } from '../../schema'; + +export const topicHandler = graphql.query< + TopicResponse, + Record<'slug', string> +>('Topic', async ({ query, variables }) => { + const { data, errors } = (await executeGraphql({ + schema, + source: query, + variableValues: variables, + rootValue: { + topic: wpTopicsFixture.find((wpTopic) => wpTopic.slug === variables.slug), + }, + })) as ExecutionResult<TopicResponse>; + + return HttpResponse.json({ data, errors }); +}); diff --git a/tests/msw/handlers/topics/topics-count.handler.ts b/tests/msw/handlers/topics/topics-count.handler.ts new file mode 100644 index 0000000..7e3dab9 --- /dev/null +++ b/tests/msw/handlers/topics/topics-count.handler.ts @@ -0,0 +1,43 @@ +import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; +import { HttpResponse, graphql } 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 { schema } from '../../schema'; + +export const topicsCountHandler = graphql.query< + TopicsCountResponse, + GraphQLPostWhere +>('TopicsCount', async ({ query, variables }) => { + const pageParams = new URLSearchParams(window.location.search); + const isError = pageParams.get('error') === 'true'; + + if (isError) return HttpResponse.json({ data: { topics: null } }); + + const { data, errors } = (await executeGraphql({ + schema, + source: query, + variableValues: variables, + rootValue: { + topics({ search, title }: typeof variables) { + const filteredTopicsByTitle = title + ? wpTopicsFixture.filter((topic) => topic.title.includes(title)) + : wpTopicsFixture; + const filteredTopics = search + ? filteredTopicsByTitle.filter((topic) => + topic.title.includes(search) + ) + : filteredTopicsByTitle; + + return getConnection({ + after: null, + data: filteredTopics, + first: undefined, + }); + }, + }, + })) as ExecutionResult<TopicsCountResponse>; + + return HttpResponse.json({ data, errors }); +}); diff --git a/tests/msw/handlers/topics/topics-list.handler.ts b/tests/msw/handlers/topics/topics-list.handler.ts new file mode 100644 index 0000000..5e3e31a --- /dev/null +++ b/tests/msw/handlers/topics/topics-list.handler.ts @@ -0,0 +1,42 @@ +import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; +import { HttpResponse, graphql } from 'msw'; +import type { + FetchTopicsListInput, + TopicsListResponse, +} from '../../../../src/services/graphql'; +import { wpTopicsFixture } from '../../../fixtures'; +import { getConnection } from '../../../utils/graphql'; +import { schema } from '../../schema'; + +export const topicsListHandler = graphql.query< + TopicsListResponse, + FetchTopicsListInput +>('TopicsList', async ({ query, variables }) => { + const pageParams = new URLSearchParams(window.location.search); + const isError = pageParams.get('error') === 'true'; + + if (isError) return HttpResponse.json({ data: { topics: null } }); + + const { data, errors } = (await executeGraphql({ + schema, + source: query, + variableValues: variables, + rootValue: { + topics({ after, first, where }: typeof variables) { + const { search, title } = where ?? {}; + const filteredTopicsByTitle = title + ? wpTopicsFixture.filter((topic) => topic.title.includes(title)) + : wpTopicsFixture; + const filteredTopics = search + ? filteredTopicsByTitle.filter((topic) => + topic.title.includes(search) + ) + : filteredTopicsByTitle; + + return getConnection({ after, data: filteredTopics, first }); + }, + }, + })) as ExecutionResult<TopicsListResponse>; + + return HttpResponse.json({ data, errors }); +}); diff --git a/tests/msw/handlers/topics/topics-slugs.handler.ts b/tests/msw/handlers/topics/topics-slugs.handler.ts new file mode 100644 index 0000000..960e411 --- /dev/null +++ b/tests/msw/handlers/topics/topics-slugs.handler.ts @@ -0,0 +1,26 @@ +import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; +import { HttpResponse, graphql } from 'msw'; +import type { TopicsSlugsResponse } from '../../../../src/services/graphql'; +import { wpTopicsFixture } from '../../../fixtures'; +import { schema } from '../../schema'; + +export const topicsSlugsHandler = graphql.query< + TopicsSlugsResponse, + Record<'first', number> +>('TopicsSlugs', async ({ query, variables }) => { + const pageParams = new URLSearchParams(window.location.search); + const isError = pageParams.get('error') === 'true'; + + if (isError) return HttpResponse.json({ data: { topics: null } }); + + const { data, errors } = (await executeGraphql({ + schema, + source: query, + variableValues: variables, + rootValue: { + topics: { nodes: wpTopicsFixture }, + }, + })) as ExecutionResult<TopicsSlugsResponse>; + + return HttpResponse.json({ data, errors }); +}); diff --git a/tests/msw/schema/types/index.ts b/tests/msw/schema/types/index.ts index c570033..ada7f2c 100644 --- a/tests/msw/schema/types/index.ts +++ b/tests/msw/schema/types/index.ts @@ -38,6 +38,18 @@ const rootQueryType = `type Query { last: Int where: RootQueryToThematicConnectionWhereArgs ): RootQueryToThematicConnection + topic( + asPreview: Boolean + id: ID! + idType: TopicIdType + ): Topic + topics( + after: String + before: String + first: Int + last: Int + where: RootQueryToTopicConnectionWhereArgs + ): RootQueryToTopicConnection }`; export const types = [ diff --git a/tests/msw/schema/types/topic.types.ts b/tests/msw/schema/types/topic.types.ts index ba9abb7..2d54653 100644 --- a/tests/msw/schema/types/topic.types.ts +++ b/tests/msw/schema/types/topic.types.ts @@ -1,4 +1,11 @@ -export const topicTypes = `union Topic_Acftopics_PostsInTopic = Post +export const topicTypes = `enum TopicIdType { + DATABASE_ID + ID + SLUG + URI +} + +union Topic_Acftopics_PostsInTopic = Post type Topic_Acftopics { officialWebsite: String @@ -16,6 +23,32 @@ type Topic { seo: PostTypeSEO slug: String title(format: PostObjectFieldFormatEnum): String +} + +input RootQueryToTopicConnectionWhereArgs { + authorName: String + orderby: [PostObjectsConnectionOrderbyInput] + search: String + title: String +} + +type RootQueryToTopicConnectionPageInfo { + endCursor: String + hasNextPage: Boolean! + hasPreviousPage: Boolean! + startCursor: String + total: Int +} + +type RootQueryToTopicConnectionEdge { + cursor: String + node: Topic! +} + +type RootQueryToTopicConnection { + edges: [RootQueryToTopicConnectionEdge!]! + nodes: [Topic!]! + pageInfo: RootQueryToTopicConnectionPageInfo! }`; // cSpell:ignore Acftopics |
