Skip to content

Commit

Permalink
move logic
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Apr 24, 2024
1 parent 8df6013 commit bcd51e0
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/testing/core/mocking/mockLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
};
}
Expand Down

0 comments on commit bcd51e0

Please sign in to comment.