aboutsummaryrefslogtreecommitdiffstats
path: root/tests/msw/handlers/thematics/thematic.handler.ts
blob: ad82ea6de155171cc710dd866c59d7ed50cdf517 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { type ExecutionResult, graphql } from 'graphql';
import { HttpResponse } from 'msw';
import type { ThematicResponse } from '../../../../src/services/graphql';
import { wpThematicsFixture } from '../../../fixtures';
import { wordpressAPI } from '../../instances';
import { schema } from '../../schema';

export const thematicHandler = wordpressAPI.query<
  ThematicResponse,
  Record<'slug', string>
>('Thematic', async ({ query, variables }) => {
  const { data, errors } = (await graphql({
    schema,
    source: query,
    variableValues: variables,
    rootValue: {
      thematic: wpThematicsFixture.find(
        (wpThematic) => wpThematic.slug === variables.slug
      ),
    },
  })) as ExecutionResult<ThematicResponse>;

  return HttpResponse.json({ data, errors });
});