@@ -2,6 +2,7 @@ import { PostgrestClient } from '../src/index'
2
2
import { Database } from './types.override'
3
3
import { expectType } from 'tsd'
4
4
import { TypeEqual } from 'ts-expect'
5
+ import { z } from 'zod'
5
6
6
7
const REST_URL = 'http://localhost:3000'
7
8
export const postgrest = new PostgrestClient < Database > ( REST_URL )
@@ -25,13 +26,17 @@ test('select with aggregate count function', async () => {
25
26
}
26
27
` )
27
28
let result : Exclude < typeof res . data , null >
28
- let expected : {
29
- username : string
30
- messages : Array < {
31
- count : number
32
- } >
33
- }
29
+ const ExpectedSchema = z . object ( {
30
+ username : z . string ( ) ,
31
+ messages : z . array (
32
+ z . object ( {
33
+ count : z . number ( ) ,
34
+ } )
35
+ ) ,
36
+ } )
37
+ let expected : z . infer < typeof ExpectedSchema >
34
38
expectType < TypeEqual < typeof result , typeof expected > > ( true )
39
+ ExpectedSchema . parse ( res . data )
35
40
} )
36
41
37
42
test ( 'select with aggregate count on a column function' , async ( ) => {
@@ -57,13 +62,17 @@ test('select with aggregate count on a column function', async () => {
57
62
}
58
63
` )
59
64
let result : Exclude < typeof res . data , null >
60
- let expected : {
61
- username : string
62
- messages : Array < {
63
- count : number
64
- } >
65
- }
65
+ const ExpectedSchema = z . object ( {
66
+ username : z . string ( ) ,
67
+ messages : z . array (
68
+ z . object ( {
69
+ count : z . number ( ) ,
70
+ } )
71
+ ) ,
72
+ } )
73
+ let expected : z . infer < typeof ExpectedSchema >
66
74
expectType < TypeEqual < typeof result , typeof expected > > ( true )
75
+ ExpectedSchema . parse ( res . data )
67
76
} )
68
77
69
78
test ( 'select with aggregate count function and alias' , async ( ) => {
@@ -89,13 +98,17 @@ test('select with aggregate count function and alias', async () => {
89
98
}
90
99
` )
91
100
let result : Exclude < typeof res . data , null >
92
- let expected : {
93
- username : string
94
- messages : Array < {
95
- message_count : number
96
- } >
97
- }
101
+ const ExpectedSchema = z . object ( {
102
+ username : z . string ( ) ,
103
+ messages : z . array (
104
+ z . object ( {
105
+ message_count : z . number ( ) ,
106
+ } )
107
+ ) ,
108
+ } )
109
+ let expected : z . infer < typeof ExpectedSchema >
98
110
expectType < TypeEqual < typeof result , typeof expected > > ( true )
111
+ ExpectedSchema . parse ( res . data )
99
112
} )
100
113
101
114
test ( 'select with aggregate nested count function' , async ( ) => {
@@ -133,15 +146,19 @@ test('select with aggregate nested count function', async () => {
133
146
}
134
147
` )
135
148
let result : Exclude < typeof res . data , null >
136
- let expected : {
137
- username : string
138
- messages : Array < {
139
- channels : {
140
- count : number
141
- }
142
- } >
143
- }
149
+ const ExpectedSchema = z . object ( {
150
+ username : z . string ( ) ,
151
+ messages : z . array (
152
+ z . object ( {
153
+ channels : z . object ( {
154
+ count : z . number ( ) ,
155
+ } ) ,
156
+ } )
157
+ ) ,
158
+ } )
159
+ let expected : z . infer < typeof ExpectedSchema >
144
160
expectType < TypeEqual < typeof result , typeof expected > > ( true )
161
+ ExpectedSchema . parse ( res . data )
145
162
} )
146
163
147
164
test ( 'select with aggregate nested count function and alias' , async ( ) => {
@@ -179,15 +196,19 @@ test('select with aggregate nested count function and alias', async () => {
179
196
}
180
197
` )
181
198
let result : Exclude < typeof res . data , null >
182
- let expected : {
183
- username : string
184
- messages : Array < {
185
- channels : {
186
- channel_count : number
187
- }
188
- } >
189
- }
199
+ const ExpectedSchema = z . object ( {
200
+ username : z . string ( ) ,
201
+ messages : z . array (
202
+ z . object ( {
203
+ channels : z . object ( {
204
+ channel_count : z . number ( ) ,
205
+ } ) ,
206
+ } )
207
+ ) ,
208
+ } )
209
+ let expected : z . infer < typeof ExpectedSchema >
190
210
expectType < TypeEqual < typeof result , typeof expected > > ( true )
211
+ ExpectedSchema . parse ( res . data )
191
212
} )
192
213
193
214
test ( 'select with aggregate sum function' , async ( ) => {
@@ -209,13 +230,17 @@ test('select with aggregate sum function', async () => {
209
230
}
210
231
` )
211
232
let result : Exclude < typeof res . data , null >
212
- let expected : {
213
- username : string
214
- messages : Array < {
215
- sum : number
216
- } >
217
- }
233
+ const ExpectedSchema = z . object ( {
234
+ username : z . string ( ) ,
235
+ messages : z . array (
236
+ z . object ( {
237
+ sum : z . number ( ) ,
238
+ } )
239
+ ) ,
240
+ } )
241
+ let expected : z . infer < typeof ExpectedSchema >
218
242
expectType < TypeEqual < typeof result , typeof expected > > ( true )
243
+ ExpectedSchema . parse ( res . data )
219
244
} )
220
245
221
246
test ( 'select with aggregate aliased sum function' , async ( ) => {
@@ -241,13 +266,17 @@ test('select with aggregate aliased sum function', async () => {
241
266
}
242
267
` )
243
268
let result : Exclude < typeof res . data , null >
244
- let expected : {
245
- username : string
246
- messages : Array < {
247
- sum_id : number
248
- } >
249
- }
269
+ const ExpectedSchema = z . object ( {
270
+ username : z . string ( ) ,
271
+ messages : z . array (
272
+ z . object ( {
273
+ sum_id : z . number ( ) ,
274
+ } )
275
+ ) ,
276
+ } )
277
+ let expected : z . infer < typeof ExpectedSchema >
250
278
expectType < TypeEqual < typeof result , typeof expected > > ( true )
279
+ ExpectedSchema . parse ( res . data )
251
280
} )
252
281
253
282
test ( 'select with aggregate sum function on nested relation' , async ( ) => {
@@ -285,13 +314,17 @@ test('select with aggregate sum function on nested relation', async () => {
285
314
}
286
315
` )
287
316
let result : Exclude < typeof res . data , null >
288
- let expected : {
289
- username : string
290
- messages : Array < {
291
- channels : {
292
- sum : number
293
- }
294
- } >
295
- }
317
+ const ExpectedSchema = z . object ( {
318
+ username : z . string ( ) ,
319
+ messages : z . array (
320
+ z . object ( {
321
+ channels : z . object ( {
322
+ sum : z . number ( ) ,
323
+ } ) ,
324
+ } )
325
+ ) ,
326
+ } )
327
+ let expected : z . infer < typeof ExpectedSchema >
296
328
expectType < TypeEqual < typeof result , typeof expected > > ( true )
329
+ ExpectedSchema . parse ( res . data )
297
330
} )
0 commit comments