@@ -3,22 +3,22 @@ import { Database } from './types.override'
33import { Database as DatabasePostgrest13 } from './types.override-with-options-postgrest13'
44import { expectType } from 'tsd'
55import { InvalidMethodError } from '../src/PostgrestFilterBuilder'
6+ import { Json } from './types.generated'
67
78const REST_URL_13 = 'http://localhost:3001'
89const postgrest13 = new PostgrestClient < DatabasePostgrest13 > ( REST_URL_13 )
910const postgrest12 = new PostgrestClient < Database > ( REST_URL_13 )
1011
1112describe ( 'maxAffected' , ( ) => {
12- // Type checking tests
13- test ( 'maxAffected should show type warning on postgrest 12 clients' , async ( ) => {
13+ test ( 'types: maxAffected should show type warning on postgrest 12 clients' , async ( ) => {
1414 const resUpdate = await postgrest12
1515 . from ( 'messages' )
1616 . update ( { channel_id : 2 } )
1717 . eq ( 'message' , 'foo' )
1818 . maxAffected ( 1 )
1919 expectType < InvalidMethodError < 'maxAffected method only available on postgrest 13+' > > ( resUpdate )
2020 } )
21- test ( 'maxAffected should show type warning on non update / delete' , async ( ) => {
21+ test ( 'types: maxAffected should show type warning on non update / delete' , async ( ) => {
2222 const resSelect = await postgrest13 . from ( 'messages' ) . select ( '*' ) . maxAffected ( 10 )
2323 const resInsert = await postgrest13
2424 . from ( 'messages' )
@@ -59,7 +59,6 @@ describe('maxAffected', () => {
5959 )
6060 } )
6161
62- // Runtime behavior tests
6362 test ( 'update should fail when maxAffected is exceeded' , async ( ) => {
6463 // First create multiple rows
6564 await postgrest13 . from ( 'messages' ) . insert ( [
@@ -74,6 +73,7 @@ describe('maxAffected', () => {
7473 . update ( { message : 'updated' } )
7574 . eq ( 'message' , 'test1' )
7675 . maxAffected ( 2 )
76+
7777 const { error } = result
7878 expect ( error ) . toBeDefined ( )
7979 expect ( error ?. code ) . toBe ( 'PGRST124' )
@@ -92,7 +92,16 @@ describe('maxAffected', () => {
9292 . eq ( 'message' , 'test2' )
9393 . maxAffected ( 2 )
9494 . select ( )
95-
95+ expectType <
96+ | {
97+ channel_id : number
98+ data : Json | null
99+ id : number
100+ message : string | null
101+ username : string
102+ } [ ]
103+ | null
104+ > ( data )
96105 expect ( error ) . toBeNull ( )
97106 expect ( data ) . toHaveLength ( 1 )
98107 expect ( data ?. [ 0 ] . message ) . toBe ( 'updated' )
@@ -113,7 +122,6 @@ describe('maxAffected', () => {
113122 . eq ( 'message' , 'test3' )
114123 . maxAffected ( 2 )
115124 . select ( )
116-
117125 expect ( error ) . toBeDefined ( )
118126 expect ( error ?. code ) . toBe ( 'PGRST124' )
119127 } )
0 commit comments