Skip to content

Commit 4c6b28c

Browse files
committed
test(api-client): enhance mutation tests for success status and parameters
1 parent 4267fb3 commit 4c6b28c

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

packages/react-client/src/tests/qraftAPIClient.test.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,8 +1281,11 @@ describe('Qraft uses Mutations', () => {
12811281
mutateWithEmptyBody,
12821282
} = result.current;
12831283

1284-
expect(mutateNoArgsWithVoidParameters.data).toBeUndefined();
1284+
expect(mutateNoArgsWithVoidParameters.isSuccess).toBeTruthy();
1285+
expect(mutateNoArgsWithVoidParameters.data).toEqual({});
1286+
expect(mutateNoArgsWithEmptyParameters.isSuccess).toBeTruthy();
12851287
expect(mutateNoArgsWithEmptyParameters.data).toEqual({});
1288+
expect(mutateWithPredefinedParameters.isSuccess).toBeTruthy();
12861289
expect(mutateWithPredefinedParameters.data).toEqual({
12871290
query: { all: 'true' },
12881291
});
@@ -1913,6 +1916,40 @@ describe('Qraft uses getMutationCache', () => {
19131916
});
19141917
});
19151918

1919+
it('supports getMutationCache().find() with status success and useMutation options mutationKey', async () => {
1920+
const { qraft, queryClient } = createClient();
1921+
const mutationKey = qraft.files.deleteFiles.getMutationKey();
1922+
1923+
const { result: mutationResult } = renderHook(
1924+
() =>
1925+
qraft.files.deleteFiles.useMutation(undefined, {
1926+
gcTime: Infinity,
1927+
mutationKey,
1928+
}),
1929+
{
1930+
wrapper: (props) => (
1931+
<Providers {...props} queryClient={queryClient} />
1932+
),
1933+
}
1934+
);
1935+
1936+
act(() => {
1937+
mutationResult.current.mutate();
1938+
});
1939+
1940+
await waitFor(() => {
1941+
expect(mutationResult.current.status).toEqual('success');
1942+
});
1943+
1944+
const foundMutation = queryClient.getMutationCache().find({
1945+
mutationKey,
1946+
status: 'success',
1947+
});
1948+
1949+
expect(foundMutation).toBeDefined();
1950+
expect(foundMutation?.state.status).toEqual('success');
1951+
});
1952+
19161953
it('supports getMutationCache().find() with partial not exact parameters', async () => {
19171954
const { qraft, queryClient } = createClient();
19181955

0 commit comments

Comments
 (0)