diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-12-06 18:20:54 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-12-07 19:12:11 +0100 |
| commit | b8eb008dd5927fb736e56699637f5f8549965eae (patch) | |
| tree | 648274babea3d3d09ed3e0f5f1fef013f94158fb /tests/msw/handlers/thematics | |
| parent | 802285872a2c57e7a5e130f32a2b45497d7687f1 (diff) | |
refactor(hooks): replace useGithubApi with useGithubRepoMeta
* use GraphQL API instead of REST (the inconvenient however is that we
now need an authorization token...)
* move fetcher in services
* add tests
* mock response using MSW
Diffstat (limited to 'tests/msw/handlers/thematics')
4 files changed, 14 insertions, 10 deletions
diff --git a/tests/msw/handlers/thematics/thematic.handler.ts b/tests/msw/handlers/thematics/thematic.handler.ts index 1e7d129..ad82ea6 100644 --- a/tests/msw/handlers/thematics/thematic.handler.ts +++ b/tests/msw/handlers/thematics/thematic.handler.ts @@ -1,14 +1,15 @@ -import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; -import { HttpResponse, graphql } from 'msw'; +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 = graphql.query< +export const thematicHandler = wordpressAPI.query< ThematicResponse, Record<'slug', string> >('Thematic', async ({ query, variables }) => { - const { data, errors } = (await executeGraphql({ + const { data, errors } = (await graphql({ schema, source: query, variableValues: variables, diff --git a/tests/msw/handlers/thematics/thematics-count.handler.ts b/tests/msw/handlers/thematics/thematics-count.handler.ts index 4bcdf2d..8a1f12e 100644 --- a/tests/msw/handlers/thematics/thematics-count.handler.ts +++ b/tests/msw/handlers/thematics/thematics-count.handler.ts @@ -1,12 +1,13 @@ import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; -import { HttpResponse, graphql } from 'msw'; +import { HttpResponse } 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 { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const thematicsCountHandler = graphql.query< +export const thematicsCountHandler = wordpressAPI.query< ThematicsCountResponse, GraphQLPostWhere >('ThematicsCount', async ({ query, variables }) => { diff --git a/tests/msw/handlers/thematics/thematics-list.handler.ts b/tests/msw/handlers/thematics/thematics-list.handler.ts index 7afec4c..790fa5a 100644 --- a/tests/msw/handlers/thematics/thematics-list.handler.ts +++ b/tests/msw/handlers/thematics/thematics-list.handler.ts @@ -1,14 +1,15 @@ import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; -import { HttpResponse, graphql } from 'msw'; +import { HttpResponse } from 'msw'; import type { FetchThematicsListInput, ThematicsListResponse, } from '../../../../src/services/graphql'; import { wpThematicsFixture } from '../../../fixtures'; import { getConnection } from '../../../utils/graphql'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const thematicsListHandler = graphql.query< +export const thematicsListHandler = wordpressAPI.query< ThematicsListResponse, FetchThematicsListInput >('ThematicsList', async ({ query, variables }) => { diff --git a/tests/msw/handlers/thematics/thematics-slugs.handler.ts b/tests/msw/handlers/thematics/thematics-slugs.handler.ts index 3a71c8e..77bbeda 100644 --- a/tests/msw/handlers/thematics/thematics-slugs.handler.ts +++ b/tests/msw/handlers/thematics/thematics-slugs.handler.ts @@ -1,10 +1,11 @@ import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; -import { HttpResponse, graphql } from 'msw'; +import { HttpResponse } from 'msw'; import type { ThematicsSlugsResponse } from '../../../../src/services/graphql'; import { wpThematicsFixture } from '../../../fixtures'; +import { wordpressAPI } from '../../instances'; import { schema } from '../../schema'; -export const thematicsSlugsHandler = graphql.query< +export const thematicsSlugsHandler = wordpressAPI.query< ThematicsSlugsResponse, Record<'first', number> >('ThematicsSlugs', async ({ query, variables }) => { |
