From bcd51e071b55c790116d7183022e83e6ed778737 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 24 Apr 2024 13:08:40 +0200 Subject: [PATCH] move logic --- src/testing/core/mocking/mockLink.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/testing/core/mocking/mockLink.ts b/src/testing/core/mocking/mockLink.ts index 1258dae115d..46e6dbd760a 100644 --- a/src/testing/core/mocking/mockLink.ts +++ b/src/testing/core/mocking/mockLink.ts @@ -214,13 +214,6 @@ ${unmatchedVars.map((d) => ` ${stringifyForDisplay(d)}`).join("\n")} newMockedResponse.request.query = query; } - newMockedResponse.request.variables = { - ...getDefaultValues( - getOperationDefinition(newMockedResponse.request.query) - ), - ...newMockedResponse.request.variables, - }; - mockedResponse.maxUsageCount = mockedResponse.maxUsageCount ?? 1; invariant( mockedResponse.maxUsageCount > 0, @@ -233,17 +226,21 @@ ${unmatchedVars.map((d) => ` ${stringifyForDisplay(d)}`).join("\n")} } private normalizeVariableMatching(mockedResponse: MockedResponse) { - const variables = mockedResponse.request.variables; - if (mockedResponse.variableMatcher && variables) { + const request = mockedResponse.request; + if (mockedResponse.variableMatcher && request.variables) { throw new Error( "Mocked response should contain either variableMatcher or request.variables" ); } if (!mockedResponse.variableMatcher) { + request.variables = { + ...getDefaultValues(getOperationDefinition(request.query)), + ...request.variables, + }; mockedResponse.variableMatcher = (vars) => { const requestVariables = vars || {}; - const mockedResponseVariables = variables || {}; + const mockedResponseVariables = request.variables || {}; return equal(requestVariables, mockedResponseVariables); }; }