Skip to content

Commit

Permalink
Fix the test
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewIngram committed Oct 2, 2024
1 parent e649395 commit a910c50
Showing 1 changed file with 52 additions and 15 deletions.
67 changes: 52 additions & 15 deletions exchanges/graphcache/src/cacheExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1552,40 +1552,69 @@ describe('directives', () => {
});
const { source: ops$, next } = makeSubject<Operation>();

const initialQuery = gql`
query {
latestTodo {
id
}
}
`;

const query = gql`
{
latestTodo {
id
text
completed @_required
author @_required {
id
name
}
}
}
`;

const operation = client.createRequestOperation('query', {
const initialQueryOperation = client.createRequestOperation('query', {
key: 1,
query: initialQuery,
variables: undefined,
});

const queryOperation = client.createRequestOperation('query', {
key: 2,
query,
variables: undefined,
});

const initialQueryResult: OperationResult = {
...queryResponse,
operation: initialQueryOperation,
data: {
__typename: 'Query',
latestTodo: {
__typename: 'Todo',
id: '1',
},
},
};

const queryResult: OperationResult = {
...queryResponse,
operation,
operation: queryOperation,
data: {
__typename: 'Query',
latestTodo: [
{
id: '1',
text: 'learn urql',
completed: null,
__typename: 'Todo',
},
],
latestTodo: {
__typename: 'Todo',
id: '1',
author: null,
},
},
};

const response = vi.fn((forwardOp: Operation): OperationResult => {
if (forwardOp.key === 1) return queryResult;
if (forwardOp.key === 1) {
return initialQueryResult;
} else if (forwardOp.key === 2) {
return queryResult;
}
return undefined as any;
});

Expand All @@ -1603,9 +1632,17 @@ describe('directives', () => {
publish
);

next(operation);
next(initialQueryOperation);
vi.runAllTimers();
next(queryOperation);
vi.runAllTimers();

expect(result.mock.calls[0][0].data).toEqual(null);
expect(result.mock.calls[0][0].data).toEqual({
latestTodo: {
id: '1',
},
});
expect(result.mock.calls[1][0].data).toEqual(null);
});
});

Expand Down

0 comments on commit a910c50

Please sign in to comment.