@@ -2,6 +2,7 @@ import { PostgrestClient } from '../src/index'
22import { Database } from './types.override'
33import { expectType } from 'tsd'
44import { TypeEqual } from 'ts-expect'
5+ import { z } from 'zod'
56
67const REST_URL = 'http://localhost:3000'
78export const postgrest = new PostgrestClient < Database > ( REST_URL )
@@ -25,13 +26,17 @@ test('select with aggregate count function', async () => {
2526 }
2627 ` )
2728 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 >
3438 expectType < TypeEqual < typeof result , typeof expected > > ( true )
39+ ExpectedSchema . parse ( res . data )
3540} )
3641
3742test ( 'select with aggregate count on a column function' , async ( ) => {
@@ -57,13 +62,17 @@ test('select with aggregate count on a column function', async () => {
5762 }
5863 ` )
5964 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 >
6674 expectType < TypeEqual < typeof result , typeof expected > > ( true )
75+ ExpectedSchema . parse ( res . data )
6776} )
6877
6978test ( 'select with aggregate count function and alias' , async ( ) => {
@@ -89,13 +98,17 @@ test('select with aggregate count function and alias', async () => {
8998 }
9099 ` )
91100 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 >
98110 expectType < TypeEqual < typeof result , typeof expected > > ( true )
111+ ExpectedSchema . parse ( res . data )
99112} )
100113
101114test ( 'select with aggregate nested count function' , async ( ) => {
@@ -133,15 +146,19 @@ test('select with aggregate nested count function', async () => {
133146 }
134147 ` )
135148 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 >
144160 expectType < TypeEqual < typeof result , typeof expected > > ( true )
161+ ExpectedSchema . parse ( res . data )
145162} )
146163
147164test ( 'select with aggregate nested count function and alias' , async ( ) => {
@@ -179,15 +196,19 @@ test('select with aggregate nested count function and alias', async () => {
179196 }
180197 ` )
181198 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 >
190210 expectType < TypeEqual < typeof result , typeof expected > > ( true )
211+ ExpectedSchema . parse ( res . data )
191212} )
192213
193214test ( 'select with aggregate sum function' , async ( ) => {
@@ -209,13 +230,17 @@ test('select with aggregate sum function', async () => {
209230 }
210231 ` )
211232 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 >
218242 expectType < TypeEqual < typeof result , typeof expected > > ( true )
243+ ExpectedSchema . parse ( res . data )
219244} )
220245
221246test ( 'select with aggregate aliased sum function' , async ( ) => {
@@ -241,13 +266,17 @@ test('select with aggregate aliased sum function', async () => {
241266 }
242267 ` )
243268 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 >
250278 expectType < TypeEqual < typeof result , typeof expected > > ( true )
279+ ExpectedSchema . parse ( res . data )
251280} )
252281
253282test ( 'select with aggregate sum function on nested relation' , async ( ) => {
@@ -285,13 +314,17 @@ test('select with aggregate sum function on nested relation', async () => {
285314 }
286315 ` )
287316 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 >
296328 expectType < TypeEqual < typeof result , typeof expected > > ( true )
329+ ExpectedSchema . parse ( res . data )
297330} )
0 commit comments