Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dulnan committed Nov 4, 2024
1 parent af7d1d3 commit 725e3d4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ Temporary Items
.apdisk

cypress/videos/
cypress/screenshots
7 changes: 4 additions & 3 deletions playground/app/plugins/graphqlConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
8 changes: 8 additions & 0 deletions test/helpers/__snapshots__/buildDocuments.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 51 additions & 1 deletion test/helpers/__snapshots__/generate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -118,6 +119,7 @@ export type Query = {
getError?: Maybe<Scalars['Boolean']['output']>;
getRequestHeader?: Maybe<Scalars['String']['output']>;
getSubmissions?: Maybe<Array<Maybe<FormSubmission>>>;
testClientOptions?: Maybe<TestClientOptions>;
testFetchOptions?: Maybe<TestFetchOptions>;
userById?: Maybe<User>;
users: Array<User>;
Expand All @@ -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<Scalars['String']['output']>;
languageFromPath?: Maybe<Scalars['String']['output']>;
};
export type TestFetchOptions = {
__typename?: 'TestFetchOptions';
headerClient?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -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; }>;
Expand Down Expand Up @@ -276,6 +296,8 @@ import type { GraphqlResponse } from '#graphql-middleware-server-options-build'
import type {
SimulateEndpointDownQuery,
FetchOptionsQuery,
TestClientOptionsQuery,
TestClientOptionsQueryVariables,
UsersQuery,
GetErrorQuery,
UserByIdQuery,
Expand All @@ -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],
Expand Down Expand Up @@ -334,6 +357,9 @@ declare module 'nitropack' {
'undefined/query/fetchOptions': {
'default': GraphqlResponse<FetchOptionsQuery>
}
'undefined/query/testClientOptions': {
'default': GraphqlResponse<TestClientOptionsQuery>
}
'undefined/query/users': {
'default': GraphqlResponse<UsersQuery>
}
Expand Down Expand Up @@ -488,6 +514,7 @@ export type Query = {
getError?: Maybe<Scalars['Boolean']['output']>;
getRequestHeader?: Maybe<Scalars['String']['output']>;
getSubmissions?: Maybe<Array<Maybe<FormSubmission>>>;
testClientOptions?: Maybe<TestClientOptions>;
testFetchOptions?: Maybe<TestFetchOptions>;
userById?: Maybe<User>;
users: Array<User>;
Expand All @@ -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<Scalars['String']['output']>;
languageFromPath?: Maybe<Scalars['String']['output']>;
};
export type TestFetchOptions = {
__typename?: 'TestFetchOptions';
headerClient?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -714,6 +752,7 @@ export type Query = {
getError?: Maybe<Scalars['Boolean']['output']>;
getRequestHeader?: Maybe<Scalars['String']['output']>;
getSubmissions?: Maybe<Array<Maybe<FormSubmission>>>;
testClientOptions?: Maybe<TestClientOptions>;
testFetchOptions?: Maybe<TestFetchOptions>;
userById?: Maybe<User>;
users: Array<User>;
Expand All @@ -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<Scalars['String']['output']>;
languageFromPath?: Maybe<Scalars['String']['output']>;
};
export type TestFetchOptions = {
__typename?: 'TestFetchOptions';
headerClient?: Maybe<Scalars['String']['output']>;
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions test/runtime/composables/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`useGraphqlMutation > Performs a mutation 1`] = `
"options": {
"body": undefined,
"method": "post",
"params": {},
},
}
`;
Expand All @@ -22,6 +23,7 @@ exports[`useGraphqlMutation > Performs a mutation with variables 1`] = `
"user": "foobar",
},
"method": "post",
"params": {},
},
}
`;
Expand All @@ -34,6 +36,7 @@ exports[`useGraphqlMutation > Throws an error for invalid mutation names. 1`] =
"options": {
"body": undefined,
"method": "post",
"params": {},
},
}
`;
Expand Down
6 changes: 6 additions & 0 deletions test/runtime/composables/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 725e3d4

Please sign in to comment.