@@ -4,63 +4,88 @@ import { createTestAppClient } from "../testing";
44import type { App } from "../types" ;
55import type { GetClientRoutes } from "../client" ;
66import { expectTypeOf } from "expect-type" ;
7+ import { z } from "zod/v4" ;
78
89describe ( "Client" , ( ) => {
9- describe ( "params" , ( ) => {
10- it ( "should apply named path params correctly" , async ( ) => {
11- const id = "one" ;
12- const expectedPath = `/api/users/${ id } ` ;
13- const expectedParams = { id } ;
10+ describe ( "inputs" , ( ) => {
11+ describe ( "params" , ( ) => {
12+ it ( "should apply named path params correctly" , async ( ) => {
13+ const id = "one" ;
14+ const expectedPath = `/api/users/${ id } ` ;
15+ const expectedParams = { id } ;
1416
15- let actual : any ;
16- const app = createApp ( ) . get (
17- "/api/users/:id" ,
18- ( ctx ) => void ( actual = ctx ) ,
19- ) ;
20- const client = createTestAppClient ( app ) ;
17+ let actual : any ;
18+ const app = createApp ( ) . get (
19+ "/api/users/:id" ,
20+ ( ctx ) => void ( actual = ctx ) ,
21+ ) ;
22+ const client = createTestAppClient ( app ) ;
23+
24+ await client . fetch ( "GET" , "/api/users/:id" , {
25+ params : { id } ,
26+ } ) ;
2127
22- await client . fetch ( "GET" , "/api/users/:id" , {
23- params : { id } ,
28+ expect ( actual . path ) . toEqual ( expectedPath ) ;
29+ expect ( actual . params ) . toEqual ( expectedParams ) ;
2430 } ) ;
2531
26- expect ( actual . path ) . toEqual ( expectedPath ) ;
27- expect ( actual . params ) . toEqual ( expectedParams ) ;
28- } ) ;
32+ it ( "should apply anonymous wildcard path params correctly" , async ( ) => {
33+ const id = "one" ;
34+ const expectedPath = `/api/users/${ id } ` ;
35+ const expectedParams = { "**" : id } ;
2936
30- it ( "should apply anonymous wildcard path params correctly" , async ( ) => {
31- const id = "one" ;
32- const expectedPath = `/api/users/${ id } ` ;
33- const expectedParams = { "**" : id } ;
37+ let actual : any ;
38+ const app = createApp ( ) . get (
39+ "/api/users/**" ,
40+ ( ctx ) => void ( actual = ctx ) ,
41+ ) ;
42+ await createTestAppClient ( app ) . fetch ( "GET" , "/api/users/**" , {
43+ params : { "**" : id } ,
44+ } ) ;
3445
35- let actual : any ;
36- const app = createApp ( ) . get (
37- "/api/users/**" ,
38- ( ctx ) => void ( actual = ctx ) ,
39- ) ;
40- await createTestAppClient ( app ) . fetch ( "GET" , "/api/users/**" , {
41- params : { "**" : id } ,
46+ expect ( actual . path ) . toEqual ( expectedPath ) ;
47+ expect ( actual . params ) . toEqual ( expectedParams ) ;
4248 } ) ;
4349
44- expect ( actual . path ) . toEqual ( expectedPath ) ;
45- expect ( actual . params ) . toEqual ( expectedParams ) ;
46- } ) ;
50+ it ( "should apply named wildcard path params correctly" , async ( ) => {
51+ const id = "one" ;
52+ const expectedPath = `/api/users/${ id } ` ;
53+ const expectedParams = { id } ;
4754
48- it ( "should apply named wildcard path params correctly" , async ( ) => {
49- const id = "one" ;
50- const expectedPath = `/api/users/${ id } ` ;
51- const expectedParams = { id } ;
55+ let actual : any ;
56+ const app = createApp ( ) . get (
57+ "/api/users/**:id" ,
58+ ( ctx ) => void ( actual = ctx ) ,
59+ ) ;
60+ await createTestAppClient ( app ) . fetch ( "GET" , "/api/users/**:id" , {
61+ params : { id } ,
62+ } ) ;
5263
53- let actual : any ;
54- const app = createApp ( ) . get (
55- "/api/users/**:id" ,
56- ( ctx ) => void ( actual = ctx ) ,
57- ) ;
58- await createTestAppClient ( app ) . fetch ( "GET" , "/api/users/**:id" , {
59- params : { id } ,
64+ expect ( actual . path ) . toEqual ( expectedPath ) ;
65+ expect ( actual . params ) . toEqual ( expectedParams ) ;
6066 } ) ;
67+ } ) ;
6168
62- expect ( actual . path ) . toEqual ( expectedPath ) ;
63- expect ( actual . params ) . toEqual ( expectedParams ) ;
69+ it ( "should require any params from the definition" , async ( ) => {
70+ const app = createApp ( ) . put (
71+ "/api/users/:id" ,
72+ {
73+ operationId : "updateUser" ,
74+ params : z . object ( {
75+ id : z . string ( ) ,
76+ } ) ,
77+ body : z . object ( {
78+ name : z . string ( ) ,
79+ } ) ,
80+ } ,
81+ ( ) => { } ,
82+ ) ;
83+ const client = createTestAppClient ( app ) ;
84+
85+ await client . fetch ( "PUT" , "/api/users/:id" , {
86+ body : { name : "test" } ,
87+ params : { id : "123" } ,
88+ } ) ;
6489 } ) ;
6590 } ) ;
6691
0 commit comments