@@ -39,3 +39,239 @@ it('Should return the expected type', () => {
3939 > ;
4040 true as test ;
4141} ) ;
42+
43+ describe ( 'ExtractRoutesFromAPI GET when query is (never, unknown, any, e.g.)' , ( ) => {
44+ it ( 'Should extract correct function signature when query is not present' , ( ) => {
45+ type APIWithNeverQuery = APIClass <
46+ '/v1' ,
47+ {
48+ method : 'GET' ;
49+ path : '/v1/endpoint.test' ;
50+ response : {
51+ 200 : ValidateFunction < unknown > ;
52+ } ;
53+ authRequired : true ;
54+ }
55+ > ;
56+ type ExpectedFunctionSignature = Expect <
57+ ShallowEqual < ExtractRoutesFromAPI < APIWithNeverQuery > [ '/v1/endpoint.test' ] [ 'GET' ] , ( params : unknown ) => unknown >
58+ > ;
59+ true as ExpectedFunctionSignature ;
60+ } ) ;
61+
62+ it ( 'Should extract correct function signature when query is never' , ( ) => {
63+ type APIWithNeverQuery = APIClass <
64+ '/v1' ,
65+ {
66+ method : 'GET' ;
67+ path : '/v1/endpoint.test' ;
68+ response : {
69+ 200 : ValidateFunction < unknown > ;
70+ } ;
71+ query : ValidateFunction < never > ;
72+ authRequired : true ;
73+ }
74+ > ;
75+ type ExpectedFunctionSignature = Expect <
76+ ShallowEqual < ExtractRoutesFromAPI < APIWithNeverQuery > [ '/v1/endpoint.test' ] [ 'GET' ] , ( params : never ) => unknown >
77+ > ;
78+ true as ExpectedFunctionSignature ;
79+ } ) ;
80+
81+ it ( 'Should extract correct function signature when query is undefined' , ( ) => {
82+ type APIWithUndefinedQuery = APIClass <
83+ '/v1' ,
84+ {
85+ method : 'GET' ;
86+ path : '/v1/endpoint.test' ;
87+ response : {
88+ 200 : ValidateFunction < unknown > ;
89+ } ;
90+ query : ValidateFunction < undefined > ;
91+ authRequired : true ;
92+ }
93+ > ;
94+ type ExpectedFunctionSignature = Expect <
95+ ShallowEqual < ExtractRoutesFromAPI < APIWithUndefinedQuery > [ '/v1/endpoint.test' ] [ 'GET' ] , ( params : undefined ) => unknown >
96+ > ;
97+ true as ExpectedFunctionSignature ;
98+ } ) ;
99+
100+ it ( 'Should extract correct function signature when query is any' , ( ) => {
101+ type APIWithAnyQuery = APIClass <
102+ '/v1' ,
103+ {
104+ method : 'GET' ;
105+ path : '/v1/endpoint.test' ;
106+ response : {
107+ 200 : ValidateFunction < unknown > ;
108+ } ;
109+ query : ValidateFunction < any > ;
110+ authRequired : true ;
111+ }
112+ > ;
113+ type ExpectedFunctionSignature = Expect <
114+ ShallowEqual < ExtractRoutesFromAPI < APIWithAnyQuery > [ '/v1/endpoint.test' ] [ 'GET' ] , ( params : unknown ) => unknown >
115+ > ;
116+ true as ExpectedFunctionSignature ;
117+ } ) ;
118+
119+ it ( 'Should extract correct function signature when query is unknown' , ( ) => {
120+ type APIWithUnknownQuery = APIClass <
121+ '/v1' ,
122+ {
123+ method : 'GET' ;
124+ path : '/v1/endpoint.test' ;
125+ response : {
126+ 200 : ValidateFunction < unknown > ;
127+ } ;
128+ query : ValidateFunction < unknown > ;
129+ authRequired : true ;
130+ }
131+ > ;
132+ type ExpectedFunctionSignature = Expect <
133+ ShallowEqual < ExtractRoutesFromAPI < APIWithUnknownQuery > [ '/v1/endpoint.test' ] [ 'GET' ] , ( params : unknown ) => unknown >
134+ > ;
135+ true as ExpectedFunctionSignature ;
136+ } ) ;
137+
138+ it ( 'Should extract correct function signature when query is null' , ( ) => {
139+ type APIWithNullQuery = APIClass <
140+ '/v1' ,
141+ {
142+ method : 'GET' ;
143+ path : '/v1/endpoint.test' ;
144+ response : {
145+ 200 : ValidateFunction < unknown > ;
146+ } ;
147+ query : ValidateFunction < null > ;
148+ authRequired : true ;
149+ }
150+ > ;
151+ type ExpectedFunctionSignature = Expect <
152+ ShallowEqual < ExtractRoutesFromAPI < APIWithNullQuery > [ '/v1/endpoint.test' ] [ 'GET' ] , ( params : null ) => unknown >
153+ > ;
154+ true as ExpectedFunctionSignature ;
155+ } ) ;
156+ } ) ;
157+
158+ describe ( 'ExtractRoutesFromAPI POST when body is (never, unknown, any, e.g.)' , ( ) => {
159+ it ( 'Should extract correct function signature when body is not present' , ( ) => {
160+ type APIWithNeverBody = APIClass <
161+ '/v1' ,
162+ {
163+ method : 'POST' ;
164+ path : '/v1/endpoint.test' ;
165+ response : {
166+ 200 : ValidateFunction < unknown > ;
167+ 201 : ValidateFunction < unknown > ;
168+ } ;
169+ authRequired : true ;
170+ }
171+ > ;
172+ type ExpectedFunctionSignature = Expect <
173+ ShallowEqual < ExtractRoutesFromAPI < APIWithNeverBody > [ '/v1/endpoint.test' ] [ 'POST' ] , ( params : unknown ) => unknown >
174+ > ;
175+ true as ExpectedFunctionSignature ;
176+ } ) ;
177+
178+ it ( 'Should extract correct function signature when body is never' , ( ) => {
179+ type APIWithNeverBody = APIClass <
180+ '/v1' ,
181+ {
182+ method : 'POST' ;
183+ path : '/v1/endpoint.test' ;
184+ response : {
185+ 200 : ValidateFunction < unknown > ;
186+ 201 : ValidateFunction < unknown > ;
187+ } ;
188+ body : ValidateFunction < never > ;
189+ authRequired : true ;
190+ }
191+ > ;
192+ type ExpectedFunctionSignature = Expect <
193+ ShallowEqual < ExtractRoutesFromAPI < APIWithNeverBody > [ '/v1/endpoint.test' ] [ 'POST' ] , ( params : never ) => unknown >
194+ > ;
195+ true as ExpectedFunctionSignature ;
196+ } ) ;
197+
198+ it ( 'Should extract correct function signature when body is undefined' , ( ) => {
199+ type APIWithUndefinedBody = APIClass <
200+ '/v1' ,
201+ {
202+ method : 'POST' ;
203+ path : '/v1/endpoint.test' ;
204+ response : {
205+ 200 : ValidateFunction < unknown > ;
206+ 201 : ValidateFunction < unknown > ;
207+ } ;
208+ body : ValidateFunction < undefined > ;
209+ authRequired : true ;
210+ }
211+ > ;
212+ type ExpectedFunctionSignature = Expect <
213+ ShallowEqual < ExtractRoutesFromAPI < APIWithUndefinedBody > [ '/v1/endpoint.test' ] [ 'POST' ] , ( params : undefined ) => unknown >
214+ > ;
215+ true as ExpectedFunctionSignature ;
216+ } ) ;
217+
218+ it ( 'Should extract correct function signature when body is any' , ( ) => {
219+ type APIWithAnyBody = APIClass <
220+ '/v1' ,
221+ {
222+ method : 'POST' ;
223+ path : '/v1/endpoint.test' ;
224+ response : {
225+ 200 : ValidateFunction < unknown > ;
226+ 201 : ValidateFunction < unknown > ;
227+ } ;
228+ body : ValidateFunction < any > ;
229+ authRequired : true ;
230+ }
231+ > ;
232+ type ExpectedFunctionSignature = Expect <
233+ ShallowEqual < ExtractRoutesFromAPI < APIWithAnyBody > [ '/v1/endpoint.test' ] [ 'POST' ] , ( params : unknown ) => unknown >
234+ > ;
235+ true as ExpectedFunctionSignature ;
236+ } ) ;
237+
238+ it ( 'Should extract correct function signature when body is unknown' , ( ) => {
239+ type APIWithUnknownBody = APIClass <
240+ '/v1' ,
241+ {
242+ method : 'POST' ;
243+ path : '/v1/endpoint.test' ;
244+ response : {
245+ 200 : ValidateFunction < unknown > ;
246+ 201 : ValidateFunction < unknown > ;
247+ } ;
248+ body : ValidateFunction < unknown > ;
249+ authRequired : true ;
250+ }
251+ > ;
252+ type ExpectedFunctionSignature = Expect <
253+ ShallowEqual < ExtractRoutesFromAPI < APIWithUnknownBody > [ '/v1/endpoint.test' ] [ 'POST' ] , ( params : unknown ) => unknown >
254+ > ;
255+ true as ExpectedFunctionSignature ;
256+ } ) ;
257+
258+ it ( 'Should extract correct function signature when body is null' , ( ) => {
259+ type APIWithNullBody = APIClass <
260+ '/v1' ,
261+ {
262+ method : 'POST' ;
263+ path : '/v1/endpoint.test' ;
264+ response : {
265+ 200 : ValidateFunction < unknown > ;
266+ 201 : ValidateFunction < unknown > ;
267+ } ;
268+ body : ValidateFunction < null > ;
269+ authRequired : true ;
270+ }
271+ > ;
272+ type ExpectedFunctionSignature = Expect <
273+ ShallowEqual < ExtractRoutesFromAPI < APIWithNullBody > [ '/v1/endpoint.test' ] [ 'POST' ] , ( params : null ) => unknown >
274+ > ;
275+ true as ExpectedFunctionSignature ;
276+ } ) ;
277+ } ) ;
0 commit comments