From 474a951c5f46daa01517eec8ce6ca6cb8f1b5a17 Mon Sep 17 00:00:00 2001 From: Eddy Nguyen Date: Mon, 15 Jul 2019 21:39:42 +1000 Subject: [PATCH] Update ResultType tests for completeness --- .../react-apollo/tests/react-apollo.spec.ts | 81 +++++++++++++++---- 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/packages/plugins/typescript/react-apollo/tests/react-apollo.spec.ts b/packages/plugins/typescript/react-apollo/tests/react-apollo.spec.ts index 8daf8103cc4..ac23d6ef159 100644 --- a/packages/plugins/typescript/react-apollo/tests/react-apollo.spec.ts +++ b/packages/plugins/typescript/react-apollo/tests/react-apollo.spec.ts @@ -840,7 +840,23 @@ export function useListenToCommentsSubscription(baseOptions?: ReactApolloHooks.S withMutationOptionsType: false, }; - it('should generate ResultType for Query', async () => { + const mutationDoc = parse(/* GraphQL */ ` + mutation test($name: String) { + submitRepository(repoFullName: $name) { + id + } + } + `); + + const subscriptionDoc = parse(/* GraphQL */ ` + subscription test($name: String) { + commentAdded(repoFullName: $name) { + id + } + } + `); + + it('should generate ResultType for Query if withResultType is true', async () => { const docs = [{ filePath: '', content: basicDoc }]; const content = (await plugin( schema, @@ -856,14 +872,23 @@ export function useListenToCommentsSubscription(baseOptions?: ReactApolloHooks.S await validateTypeScript(content, schema, docs, {}); }); - it('should generate ResultType for Mutation', async () => { - const mutationDoc = parse(/* GraphQL */ ` - mutation test($name: String) { - submitRepository(repoFullName: $name) { - id - } + it('should NOT generate ResultType for Query if withResultType is false', async () => { + const docs = [{ filePath: '', content: basicDoc }]; + const content = (await plugin( + schema, + docs, + { ...config, withResultType: false }, + { + outputFile: 'graphql.tsx', } - `); + )) as Types.ComplexPluginOutput; + + expect(content.prepend).not.toContain(`import * as ReactApollo from 'react-apollo';`); + expect(content.content).not.toContain(`export type TestQueryResult = ReactApollo.QueryResult;`); + await validateTypeScript(content, schema, docs, {}); + }); + + it('should generate ResultType for Mutation if withResultType is true', async () => { const docs = [{ filePath: '', content: mutationDoc }]; const content = (await plugin( @@ -880,15 +905,24 @@ export function useListenToCommentsSubscription(baseOptions?: ReactApolloHooks.S await validateTypeScript(content, schema, docs, {}); }); - it('should generate ResultType for Subscription', async () => { - const subscriptionDoc = parse(/* GraphQL */ ` - subscription test($name: String) { - commentAdded(repoFullName: $name) { - id - } + it('should NOT generate ResultType for Mutation if withResultType is false', async () => { + const docs = [{ filePath: '', content: mutationDoc }]; + + const content = (await plugin( + schema, + docs, + { ...config, withResultType: false }, + { + outputFile: 'graphql.tsx', } - `); + )) as Types.ComplexPluginOutput; + expect(content.prepend).not.toContain(`import * as ReactApollo from 'react-apollo';`); + expect(content.content).not.toContain(`export type TestMutationResult = ReactApollo.MutationResult;`); + await validateTypeScript(content, schema, docs, {}); + }); + + it('should generate ResultType for Subscription if withResultType is true', async () => { const docs = [{ filePath: '', content: subscriptionDoc }]; const content = (await plugin( @@ -904,6 +938,23 @@ export function useListenToCommentsSubscription(baseOptions?: ReactApolloHooks.S expect(content.content).toContain(`export type TestSubscriptionResult = ReactApollo.SubscriptionResult;`); await validateTypeScript(content, schema, docs, {}); }); + + it('should NOT generate ResultType for Subscription if withResultType is false', async () => { + const docs = [{ filePath: '', content: subscriptionDoc }]; + + const content = (await plugin( + schema, + docs, + { ...config, withResultType: false }, + { + outputFile: 'graphql.tsx', + } + )) as Types.ComplexPluginOutput; + + expect(content.prepend).not.toContain(`import * as ReactApollo from 'react-apollo';`); + expect(content.content).not.toContain(`export type TestSubscriptionResult = ReactApollo.SubscriptionResult;`); + await validateTypeScript(content, schema, docs, {}); + }); }); describe('MutationOptions', () => {