From 64ca985e2a751f2ba5d778fad7dda0305e6ea90d Mon Sep 17 00:00:00 2001 From: nayni Date: Sat, 10 Mar 2018 14:50:26 +0100 Subject: [PATCH] improve test coverage --- .../graphql-resolve-batch-tests.ts | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/types/graphql-resolve-batch/graphql-resolve-batch-tests.ts b/types/graphql-resolve-batch/graphql-resolve-batch-tests.ts index 519a3a4088..9043cdaf0e 100644 --- a/types/graphql-resolve-batch/graphql-resolve-batch-tests.ts +++ b/types/graphql-resolve-batch/graphql-resolve-batch-tests.ts @@ -16,6 +16,14 @@ interface SomeTestResult { someTestResultProp: string; } +const batchFunction = (sources: ReadonlyArray) => { + const someTestResult: SomeTestResult = { + someTestResultProp: "Hello" + }; + + return sources.map(source => someTestResult); +}; + const asyncBatchFunction = async (sources: ReadonlyArray) => { return new Promise(resolve => { const res = [ @@ -27,19 +35,35 @@ const asyncBatchFunction = async (sources: ReadonlyArray) => { }); }; +const asyncBatchFunctionWhenTReturnIsArray = async ( + sources: ReadonlyArray +) => { + const sourceBatches = sources.map(() => { + return new Promise(resolve => { + const res = [ + { + someTestResultProp: "" + } + ]; + resolve(res); + }); + }); + + return Promise.all(sourceBatches); +}; + +// $ExpectType ResolverFunction const withSourceAndResultTyped = createBatchResolver< SomeTestSource, SomeTestResult >((sources, _, __) => { - return sources.map(source => { - const res: SomeTestResult = { - someTestResultProp: "" - }; + // $ExpectType ReadonlyArray + const verifySources = sources; - return res; - }); + return batchFunction(sources); }); +// $ExpectType ResolverFunction const withSourceAndResultTypedAsPromise = createBatchResolver< SomeTestSource, SomeTestResult @@ -50,6 +74,7 @@ const withSourceAndResultTypedAsPromise = createBatchResolver< return result; }); +// $ExpectType ResolverFunction const withSourceAndArgsAndResultTyped = createBatchResolver< SomeTestSource, SomeTestResult, @@ -64,6 +89,7 @@ const withSourceAndArgsAndResultTyped = createBatchResolver< return result; }); +// $ExpectType ResolverFunction const withSourceAndArgsAndContextTyped = createBatchResolver< SomeTestSource, SomeTestResult, @@ -80,3 +106,13 @@ const withSourceAndArgsAndContextTyped = createBatchResolver< const result = await asyncBatchFunction(sources); return result; }); + +// $ExpectType ResolverFunction +const withResultIsArray = createBatchResolver( + (sources, _, __) => { + // $ExpectType ReadonlyArray + const verifySources = sources; + + return asyncBatchFunctionWhenTReturnIsArray(sources); + } +);