From 725e3d4edd17661894ee5bf3e0d437f81193e96e Mon Sep 17 00:00:00 2001 From: Jan Hug Date: Mon, 4 Nov 2024 16:33:04 +0100 Subject: [PATCH] fix tests --- .gitignore | 1 + playground/app/plugins/graphqlConfig.ts | 7 +-- .../__snapshots__/buildDocuments.test.ts.snap | 8 +++ .../__snapshots__/generate.test.ts.snap | 52 ++++++++++++++++++- test/helpers/generate.test.ts | 2 +- .../__snapshots__/index.test.ts.snap | 3 ++ test/runtime/composables/index.test.ts | 6 +++ 7 files changed, 74 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 9e47419..f2b5d3b 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,4 @@ Temporary Items .apdisk cypress/videos/ +cypress/screenshots diff --git a/playground/app/plugins/graphqlConfig.ts b/playground/app/plugins/graphqlConfig.ts index bfae5f4..a1acec5 100644 --- a/playground/app/plugins/graphqlConfig.ts +++ b/playground/app/plugins/graphqlConfig.ts @@ -27,9 +27,10 @@ export default defineNuxtPlugin({ options.headers = new Headers() } - // @ts-ignore - options.headers['x-nuxt-header-client'] = - 'The header value from the client' + options.headers.set( + 'x-nuxt-header-client', + 'The header value from the client', + ) options.params.t = Date.now() options.params.lang_from_plugin = language.value }, diff --git a/test/helpers/__snapshots__/buildDocuments.test.ts.snap b/test/helpers/__snapshots__/buildDocuments.test.ts.snap index abcb8de..55a7309 100644 --- a/test/helpers/__snapshots__/buildDocuments.test.ts.snap +++ b/test/helpers/__snapshots__/buildDocuments.test.ts.snap @@ -8,6 +8,14 @@ exports[`buildDocuments > Reads and build the documents by pattern 1`] = ` }", "filename": "mutation.initState.graphql", }, + { + "content": "query testClientOptions($path: String!) { + testClientOptions(path: $path) { + language + } +}", + "filename": "query.testClientOptions.graphql", + }, { "content": "query getCurrentTime { time: getCurrentTime diff --git a/test/helpers/__snapshots__/generate.test.ts.snap b/test/helpers/__snapshots__/generate.test.ts.snap index cd1c5b6..2b5c3b6 100644 --- a/test/helpers/__snapshots__/generate.test.ts.snap +++ b/test/helpers/__snapshots__/generate.test.ts.snap @@ -6,6 +6,7 @@ exports[`generate > Generates templates correctly for auto imported documents 1` "query": { "simulateEndpointDown": "query simulateEndpointDown {\\n testFetchOptions {\\n headerClient\\n headerServer\\n }\\n}", "fetchOptions": "query fetchOptions {\\n testFetchOptions {\\n headerClient\\n headerServer\\n }\\n}", + "testClientOptions": "query testClientOptions($path: String!) {\\n testClientOptions(path: $path) {\\n language\\n }\\n}", "users": "query users {\\n users {\\n ...user\\n }\\n}\\n\\nfragment user on User {\\n id\\n firstName\\n lastName\\n email\\n description\\n dateOfBirth\\n}", "getError": "query getError {\\n getError\\n}", "userById": "query userById($id: ID!) {\\n userById(id: $id) {\\n ...user\\n }\\n}\\n\\nfragment user on User {\\n id\\n firstName\\n lastName\\n email\\n description\\n dateOfBirth\\n}", @@ -118,6 +119,7 @@ export type Query = { getError?: Maybe; getRequestHeader?: Maybe; getSubmissions?: Maybe>>; + testClientOptions?: Maybe; testFetchOptions?: Maybe; userById?: Maybe; users: Array; @@ -129,10 +131,21 @@ export type QueryGetRequestHeaderArgs = { }; +export type QueryTestClientOptionsArgs = { + path: Scalars['String']['input']; +}; + + export type QueryUserByIdArgs = { id: Scalars['ID']['input']; }; +export type TestClientOptions = { + __typename?: 'TestClientOptions'; + language?: Maybe; + languageFromPath?: Maybe; +}; + export type TestFetchOptions = { __typename?: 'TestFetchOptions'; headerClient?: Maybe; @@ -191,6 +204,13 @@ export type FetchOptionsQuery = { __typename?: 'Query', testFetchOptions?: { __t export type UserFragment = { __typename?: 'User', id: number, firstName: string, lastName: string, email: string, description?: string | null, dateOfBirth?: string | null }; +export type TestClientOptionsQueryVariables = Exact<{ + path: Scalars['String']['input']; +}>; + + +export type TestClientOptionsQuery = { __typename?: 'Query', testClientOptions?: { __typename?: 'TestClientOptions', language?: string | null } | null }; + export type UsersQueryVariables = Exact<{ [key: string]: never; }>; @@ -276,6 +296,8 @@ import type { GraphqlResponse } from '#graphql-middleware-server-options-build' import type { SimulateEndpointDownQuery, FetchOptionsQuery, + TestClientOptionsQuery, + TestClientOptionsQueryVariables, UsersQuery, GetErrorQuery, UserByIdQuery, @@ -300,10 +322,11 @@ import type { declare module '#build/nuxt-graphql-middleware' { - export type GraphqlMiddlewareResponseUnion = SimulateEndpointDownQuery | FetchOptionsQuery | UsersQuery | GetErrorQuery | UserByIdQuery | FetchOptionsComposableQuery | GetSubmissionsQuery | FoobarQuery | QueryTwoQuery | QueryOneQuery | GetCurrentTimeQuery | TestUploadMutation | TestFormSubmitMutation | InitStateMutation | AddUserMutation | TriggerErrorMutation | DeleteUserMutation + export type GraphqlMiddlewareResponseUnion = SimulateEndpointDownQuery | FetchOptionsQuery | TestClientOptionsQuery | UsersQuery | GetErrorQuery | UserByIdQuery | FetchOptionsComposableQuery | GetSubmissionsQuery | FoobarQuery | QueryTwoQuery | QueryOneQuery | GetCurrentTimeQuery | TestUploadMutation | TestFormSubmitMutation | InitStateMutation | AddUserMutation | TriggerErrorMutation | DeleteUserMutation export type GraphqlMiddlewareQuery = { simulateEndpointDown: [null, true, SimulateEndpointDownQuery], fetchOptions: [null, true, FetchOptionsQuery], + testClientOptions: [TestClientOptionsQueryVariables, false, TestClientOptionsQuery], users: [null, true, UsersQuery], getError: [null, true, GetErrorQuery], userById: [UserByIdQueryVariables, false, UserByIdQuery], @@ -334,6 +357,9 @@ declare module 'nitropack' { 'undefined/query/fetchOptions': { 'default': GraphqlResponse } + 'undefined/query/testClientOptions': { + 'default': GraphqlResponse + } 'undefined/query/users': { 'default': GraphqlResponse } @@ -488,6 +514,7 @@ export type Query = { getError?: Maybe; getRequestHeader?: Maybe; getSubmissions?: Maybe>>; + testClientOptions?: Maybe; testFetchOptions?: Maybe; userById?: Maybe; users: Array; @@ -499,10 +526,21 @@ export type QueryGetRequestHeaderArgs = { }; +export type QueryTestClientOptionsArgs = { + path: Scalars['String']['input']; +}; + + export type QueryUserByIdArgs = { id: Scalars['ID']['input']; }; +export type TestClientOptions = { + __typename?: 'TestClientOptions'; + language?: Maybe; + languageFromPath?: Maybe; +}; + export type TestFetchOptions = { __typename?: 'TestFetchOptions'; headerClient?: Maybe; @@ -714,6 +752,7 @@ export type Query = { getError?: Maybe; getRequestHeader?: Maybe; getSubmissions?: Maybe>>; + testClientOptions?: Maybe; testFetchOptions?: Maybe; userById?: Maybe; users: Array; @@ -725,10 +764,21 @@ export type QueryGetRequestHeaderArgs = { }; +export type QueryTestClientOptionsArgs = { + path: Scalars['String']['input']; +}; + + export type QueryUserByIdArgs = { id: Scalars['ID']['input']; }; +export type TestClientOptions = { + __typename?: 'TestClientOptions'; + language?: Maybe; + languageFromPath?: Maybe; +}; + export type TestFetchOptions = { __typename?: 'TestFetchOptions'; headerClient?: Maybe; diff --git a/test/helpers/generate.test.ts b/test/helpers/generate.test.ts index 02b23dd..9060afc 100644 --- a/test/helpers/generate.test.ts +++ b/test/helpers/generate.test.ts @@ -42,7 +42,7 @@ describe('generate', () => { ) expect(result.documents.filter((v) => v.errors?.length)).toEqual([]) expect(result.hasErrors).toBeFalsy() - expect(result.documents).toHaveLength(18) + expect(result.documents).toHaveLength(19) expect(result.templates).toHaveLength(3) const a = result.templates.find( diff --git a/test/runtime/composables/__snapshots__/index.test.ts.snap b/test/runtime/composables/__snapshots__/index.test.ts.snap index 3f6e79c..24761b4 100644 --- a/test/runtime/composables/__snapshots__/index.test.ts.snap +++ b/test/runtime/composables/__snapshots__/index.test.ts.snap @@ -8,6 +8,7 @@ exports[`useGraphqlMutation > Performs a mutation 1`] = ` "options": { "body": undefined, "method": "post", + "params": {}, }, } `; @@ -22,6 +23,7 @@ exports[`useGraphqlMutation > Performs a mutation with variables 1`] = ` "user": "foobar", }, "method": "post", + "params": {}, }, } `; @@ -34,6 +36,7 @@ exports[`useGraphqlMutation > Throws an error for invalid mutation names. 1`] = "options": { "body": undefined, "method": "post", + "params": {}, }, } `; diff --git a/test/runtime/composables/index.test.ts b/test/runtime/composables/index.test.ts index f4d2bc6..b712b47 100644 --- a/test/runtime/composables/index.test.ts +++ b/test/runtime/composables/index.test.ts @@ -42,6 +42,12 @@ vi.mock('#imports', () => { } }) +vi.mock('#graphql-middleware-client-options', () => { + return { + clientOptions: {}, + } +}) + const fetchMock = (endpoint: string, options: any) => { return Promise.resolve({ data: undefined,