Skip to content

Commit 3e13fcc

Browse files
committed
add test for fat trigger api shape
1 parent 0f39297 commit 3e13fcc

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@gadget-client/app-with-no-user-model": "^1.3.0",
2525
"@gadget-client/bulk-actions-test": "^1.102.0",
2626
"@gadget-client/related-products-example": "^1.848.0",
27-
"@gadget-client/super-auth": "^1.17.0",
27+
"@gadget-client/super-auth": "^1.27.0",
2828
"@gadgetinc/api-client-core": "workspace:*",
2929
"@gadgetinc/eslint-config": "^0.6.1",
3030
"@gadgetinc/prettier-config": "^0.4.0",

packages/react/spec/useAction.spec.tsx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { AnyVariables } from "urql";
88
import { Provider } from "../src/GadgetProvider.js";
99
import { useAction } from "../src/index.js";
1010
import type { ErrorWrapper } from "../src/utils.js";
11-
import { relatedProductsApi } from "./apis.js";
11+
import { relatedProductsApi, superAuthApi } from "./apis.js";
1212
import { MockClientWrapper, createMockUrqlClient, mockUrqlClient } from "./testWrappers.js";
1313

1414
describe("useAction", () => {
@@ -417,6 +417,54 @@ describe("useAction", () => {
417417
`);
418418
});
419419

420+
test("generates correct mutation and variables for fat trigger", async () => {
421+
let variables: AnyVariables;
422+
423+
const client = createMockUrqlClient({
424+
mutationAssertions: (request) => {
425+
variables = request.variables;
426+
},
427+
});
428+
429+
const wrapper = (props: { children: React.ReactNode }) => <Provider value={client}>{props.children}</Provider>;
430+
431+
const { result } = renderHook(() => useAction(superAuthApi.user.signUp), {
432+
wrapper,
433+
});
434+
435+
let mutationPromise: any;
436+
act(() => {
437+
mutationPromise = result.current[1]({ email: "[email protected]", password: "password123!" });
438+
});
439+
440+
client.executeMutation.pushResponse("signUpUser", {
441+
data: {
442+
signUpUser: {
443+
result: {
444+
result: "ok",
445+
},
446+
success: true,
447+
},
448+
},
449+
stale: false,
450+
hasNext: false,
451+
});
452+
453+
await act(async () => {
454+
const promiseResult = await mutationPromise;
455+
expect(promiseResult.data).toEqual({ result: "ok" });
456+
expect(promiseResult.fetching).toBe(false);
457+
expect(promiseResult.error).toBeFalsy();
458+
});
459+
460+
expect(variables).toMatchInlineSnapshot(`
461+
{
462+
"email": "[email protected]",
463+
"password": "password123!",
464+
}
465+
`);
466+
});
467+
420468
test("should throw if called without a model api identifier and there is an ambiguous field", async () => {
421469
let caughtError = null;
422470

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)