@@ -136,4 +136,45 @@ describe('maxAffected', () => {
136
136
expect ( data ) . toHaveLength ( 1 )
137
137
expect ( data ?. [ 0 ] . message ) . toBe ( 'test4' )
138
138
} )
139
+
140
+ test ( 'should be able to use .maxAffected with setof records returning rpc' , async ( ) => {
141
+ // First create a user that will be returned by the RPC
142
+ await postgrest13 . from ( 'users' ) . insert ( [ { username : 'testuser' , status : 'ONLINE' } ] )
143
+ // Call the RPC function that returns a set of records
144
+ const { data, error } = await postgrest13
145
+ . rpc ( 'set_users_offline' , { name_param : 'testuser' } )
146
+ . maxAffected ( 1 )
147
+ . select ( )
148
+
149
+ expect ( error ) . toBeNull ( )
150
+ expect ( data ) . toHaveLength ( 1 )
151
+ expect ( data ) . toEqual ( [
152
+ {
153
+ username : 'testuser' ,
154
+ data : null ,
155
+ age_range : null ,
156
+ status : 'OFFLINE' ,
157
+ catchphrase : null ,
158
+ } ,
159
+ ] )
160
+ } )
161
+
162
+ test ( 'should fail when rpc returns more results than maxAffected' , async ( ) => {
163
+ // First create multiple users that will be returned by the RPC
164
+ await postgrest13 . from ( 'users' ) . insert ( [
165
+ { username : 'testuser1' , status : 'ONLINE' } ,
166
+ { username : 'testuser2' , status : 'ONLINE' } ,
167
+ { username : 'testuser3' , status : 'ONLINE' } ,
168
+ ] )
169
+
170
+ // Call the RPC function that returns a set of records
171
+ const { data, error } = await postgrest13
172
+ . rpc ( 'set_users_offline' , { name_param : 'testuser%' } )
173
+ . maxAffected ( 1 )
174
+ . select ( )
175
+
176
+ expect ( error ) . toBeDefined ( )
177
+ expect ( error ?. code ) . toBe ( 'PGRST124' )
178
+ expect ( data ) . toBeNull ( )
179
+ } )
139
180
} )
0 commit comments