@@ -473,6 +473,48 @@ describe("useDataConnectMutation", () => {
473
473
) ;
474
474
} ) ;
475
475
476
+ test ( "invalidates queries specified in the invalidate option as a QueryKey" , async ( ) => {
477
+ const movieData = {
478
+ title : "tanstack query firebase" ,
479
+ genre : "library" ,
480
+ imageUrl : "https://invertase.io/" ,
481
+ } ;
482
+
483
+ const createdMovie = await createMovie ( movieData ) ;
484
+
485
+ const movieId = createdMovie ?. data ?. movie_insert ?. id ;
486
+
487
+ const { result } = renderHook (
488
+ ( ) =>
489
+ useDataConnectMutation ( createMovieRef , {
490
+ invalidate : [ [ "GetMovieById" , { id : movieId } ] ] ,
491
+ } ) ,
492
+ {
493
+ wrapper,
494
+ } ,
495
+ ) ;
496
+ const movie = {
497
+ title : "TanStack Query Firebase" ,
498
+ genre : "invalidate_option_test" ,
499
+ imageUrl : "https://test-image-url.com/" ,
500
+ } ;
501
+
502
+ await act ( async ( ) => {
503
+ await result . current . mutateAsync ( movie ) ;
504
+ } ) ;
505
+
506
+ await waitFor ( ( ) => {
507
+ expect ( result . current . status ) . toBe ( "success" ) ;
508
+ } ) ;
509
+
510
+ expect ( invalidateQueriesSpy . mock . calls ) . toHaveLength ( 1 ) ;
511
+ expect ( invalidateQueriesSpy ) . toHaveBeenCalledWith (
512
+ expect . objectContaining ( {
513
+ queryKey : [ "GetMovieById" , { id : movieId } ] ,
514
+ } ) ,
515
+ ) ;
516
+ } ) ;
517
+
476
518
test ( "invalidates queries specified in the invalidate option for create mutations with both variable and non-variable refs" , async ( ) => {
477
519
const movieData = {
478
520
title : "tanstack query firebase" ,
@@ -1015,4 +1057,65 @@ describe("useDataConnectMutation", () => {
1015
1057
expect ( deleteMutationResult . current . data ?. movie_delete ?. id ) . toBe ( movieId ) ;
1016
1058
} ) ;
1017
1059
} ) ;
1060
+
1061
+ test ( "executes mutation successfully with function ref" , async ( ) => {
1062
+ const movie = {
1063
+ title : "TanStack Query Firebase" ,
1064
+ genre : "library" ,
1065
+ imageUrl : "https://test-image-url.com/" ,
1066
+ } ;
1067
+
1068
+ const { result } = renderHook (
1069
+ ( ) => useDataConnectMutation ( ( ) => createMovieRef ( movie ) ) ,
1070
+ {
1071
+ wrapper,
1072
+ } ,
1073
+ ) ;
1074
+
1075
+ await act ( async ( ) => {
1076
+ await result . current . mutateAsync ( ) ;
1077
+ } ) ;
1078
+
1079
+ await waitFor ( ( ) => {
1080
+ expect ( result . current . isSuccess ) . toBe ( true ) ;
1081
+ expect ( result . current . data ) . toHaveProperty ( "movie_insert" ) ;
1082
+ expect ( result . current . data ?. movie_insert ) . toMatchObject ( {
1083
+ title : movie . title ,
1084
+ genre : movie . genre ,
1085
+ imageUrl : movie . imageUrl ,
1086
+ } ) ;
1087
+ } ) ;
1088
+ } ) ;
1089
+
1090
+ test ( "executes mutation successfully with function ref that accepts variables" , async ( ) => {
1091
+ const { result } = renderHook (
1092
+ ( ) =>
1093
+ useDataConnectMutation ( ( title : string ) =>
1094
+ createMovieRef ( {
1095
+ title,
1096
+ genre : "library" ,
1097
+ imageUrl : "https://test-image-url.com/" ,
1098
+ } ) ,
1099
+ ) ,
1100
+ {
1101
+ wrapper,
1102
+ } ,
1103
+ ) ;
1104
+
1105
+ const movieTitle = "TanStack Query Firebase" ;
1106
+
1107
+ await act ( async ( ) => {
1108
+ await result . current . mutateAsync ( movieTitle ) ;
1109
+ } ) ;
1110
+
1111
+ await waitFor ( ( ) => {
1112
+ expect ( result . current . isSuccess ) . toBe ( true ) ;
1113
+ expect ( result . current . data ) . toHaveProperty ( "movie_insert" ) ;
1114
+ expect ( result . current . data ?. movie_insert ) . toMatchObject ( {
1115
+ title : movieTitle ,
1116
+ genre : "library" ,
1117
+ imageUrl : "https://test-image-url.com/" ,
1118
+ } ) ;
1119
+ } ) ;
1120
+ } ) ;
1018
1121
} ) ;
0 commit comments