@@ -98,6 +98,41 @@ describe('basic lifecycle', () => {
98
98
onSuccess . mockReset ( )
99
99
} )
100
100
101
+ test ( 'Does basic inserts and upserts' , async ( ) => {
102
+ const newPost : Post = {
103
+ id : '3' ,
104
+ contents : 'Inserted content' ,
105
+ title : 'Inserted title' ,
106
+ }
107
+ const insertPromise = storeRef . store . dispatch (
108
+ api . util . upsertQueryData ( 'post' , newPost . id , newPost )
109
+ )
110
+
111
+ await insertPromise
112
+
113
+ const selectPost3 = api . endpoints . post . select ( newPost . id )
114
+ const insertedPostEntry = selectPost3 ( storeRef . store . getState ( ) )
115
+ expect ( insertedPostEntry . isSuccess ) . toBe ( true )
116
+ expect ( insertedPostEntry . data ) . toEqual ( newPost )
117
+
118
+ const updatedPost : Post = {
119
+ id : '3' ,
120
+ contents : 'Updated content' ,
121
+ title : 'Updated title' ,
122
+ }
123
+
124
+ const updatePromise = storeRef . store . dispatch (
125
+ api . util . upsertQueryData ( 'post' , updatedPost . id , updatedPost )
126
+ )
127
+
128
+ await updatePromise
129
+
130
+ const updatedPostEntry = selectPost3 ( storeRef . store . getState ( ) )
131
+
132
+ expect ( updatedPostEntry . isSuccess ) . toBe ( true )
133
+ expect ( updatedPostEntry . data ) . toEqual ( updatedPost )
134
+ } )
135
+
101
136
test ( 'success' , async ( ) => {
102
137
const { result } = renderHook (
103
138
( ) => extendedApi . endpoints . test . useMutation ( ) ,
0 commit comments