diff options
Diffstat (limited to 'tests/msw/handlers/thematics/thematics-slugs.handler.ts')
| -rw-r--r-- | tests/msw/handlers/thematics/thematics-slugs.handler.ts | 26 |
1 files changed, 26 insertions, 0 deletions
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 }); +}); |
