aboutsummaryrefslogtreecommitdiffstats
path: root/tests/msw/handlers/thematics/thematics-count.handler.ts
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-28 16:18:03 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-28 18:04:24 +0100
commitf564d181bc428e25a02bf1d98c4449a6b3eb8e9e (patch)
tree6057a1e3a419957fb32d1a08160d5d746e54bc04 /tests/msw/handlers/thematics/thematics-count.handler.ts
parent180134883b281883246fc9909b1d494363861144 (diff)
fix(services,types): make coherent Thematic type and query
* some nodes was queried but missing in the Thematic type and vice versa, it is now fixed * add tests for all thematics fetchers
Diffstat (limited to 'tests/msw/handlers/thematics/thematics-count.handler.ts')
-rw-r--r--tests/msw/handlers/thematics/thematics-count.handler.ts45
1 files changed, 45 insertions, 0 deletions
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 });
+});