@@ -8,7 +8,7 @@ import type { AnyVariables } from "urql";
8
8
import { Provider } from "../src/GadgetProvider.js" ;
9
9
import { useAction } from "../src/index.js" ;
10
10
import type { ErrorWrapper } from "../src/utils.js" ;
11
- import { relatedProductsApi } from "./apis.js" ;
11
+ import { relatedProductsApi , superAuthApi } from "./apis.js" ;
12
12
import { MockClientWrapper , createMockUrqlClient , mockUrqlClient } from "./testWrappers.js" ;
13
13
14
14
describe ( "useAction" , ( ) => {
@@ -417,6 +417,54 @@ describe("useAction", () => {
417
417
` ) ;
418
418
} ) ;
419
419
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
+
463
+ "password": "password123!",
464
+ }
465
+ ` ) ;
466
+ } ) ;
467
+
420
468
test ( "should throw if called without a model api identifier and there is an ambiguous field" , async ( ) => {
421
469
let caughtError = null ;
422
470
0 commit comments