@@ -1232,25 +1232,68 @@ describe('standalone adapter', () => {
1232
1232
1233
1233
test ( 'with coerce' , async ( ) => {
1234
1234
const appRouter = t . router ( {
1235
- plusOne : t . procedure
1235
+ getPlusOne : t . procedure
1236
1236
. meta ( { openapi : { method : 'GET' , path : '/plus-one' } } )
1237
1237
. input ( z . object ( { number : z . number ( ) } ) )
1238
1238
. output ( z . object ( { result : z . number ( ) } ) )
1239
1239
. query ( ( { input } ) => ( { result : input . number + 1 } ) ) ,
1240
+ postPlusOne : t . procedure
1241
+ . meta ( { openapi : { method : 'POST' , path : '/plus-one' } } )
1242
+ . input ( z . object ( { date : z . date ( ) } ) )
1243
+ . output ( z . object ( { result : z . number ( ) } ) )
1244
+ . mutation ( ( { input } ) => ( { result : input . date . getTime ( ) + 1 } ) ) ,
1245
+ pathPlusOne : t . procedure
1246
+ . meta ( { openapi : { method : 'GET' , path : '/plus-one/{number}' } } )
1247
+ . input ( z . object ( { number : z . number ( ) } ) )
1248
+ . output ( z . object ( { result : z . number ( ) } ) )
1249
+ . query ( ( { input } ) => ( { result : input . number + 1 } ) ) ,
1240
1250
} ) ;
1241
1251
1242
1252
const { url, close } = createHttpServerWithRouter ( {
1243
1253
router : appRouter ,
1244
1254
} ) ;
1245
1255
1246
- const res = await fetch ( `${ url } /plus-one?number=9` , { method : 'GET' } ) ;
1247
- const body = await res . json ( ) ;
1256
+ {
1257
+ const res = await fetch ( `${ url } /plus-one?number=9` , { method : 'GET' } ) ;
1258
+ const body = await res . json ( ) ;
1248
1259
1249
- expect ( res . status ) . toBe ( 200 ) ;
1250
- expect ( body ) . toEqual ( { result : 10 } ) ;
1251
- expect ( createContextMock ) . toHaveBeenCalledTimes ( 1 ) ;
1252
- expect ( responseMetaMock ) . toHaveBeenCalledTimes ( 1 ) ;
1253
- expect ( onErrorMock ) . toHaveBeenCalledTimes ( 0 ) ;
1260
+ expect ( res . status ) . toBe ( 200 ) ;
1261
+ expect ( body ) . toEqual ( { result : 10 } ) ;
1262
+ expect ( createContextMock ) . toHaveBeenCalledTimes ( 1 ) ;
1263
+ expect ( responseMetaMock ) . toHaveBeenCalledTimes ( 1 ) ;
1264
+ expect ( onErrorMock ) . toHaveBeenCalledTimes ( 0 ) ;
1265
+
1266
+ clearMocks ( ) ;
1267
+ }
1268
+ {
1269
+ const date = new Date ( ) ;
1270
+
1271
+ const res = await fetch ( `${ url } /plus-one` , {
1272
+ method : 'POST' ,
1273
+ headers : { 'Content-Type' : 'application/json' } ,
1274
+ body : JSON . stringify ( { date } ) ,
1275
+ } ) ;
1276
+ const body = await res . json ( ) ;
1277
+
1278
+ expect ( res . status ) . toBe ( 200 ) ;
1279
+ expect ( body ) . toEqual ( { result : date . getTime ( ) + 1 } ) ;
1280
+ expect ( createContextMock ) . toHaveBeenCalledTimes ( 1 ) ;
1281
+ expect ( responseMetaMock ) . toHaveBeenCalledTimes ( 1 ) ;
1282
+ expect ( onErrorMock ) . toHaveBeenCalledTimes ( 0 ) ;
1283
+
1284
+ clearMocks ( ) ;
1285
+ }
1286
+
1287
+ {
1288
+ const res = await fetch ( `${ url } /plus-one/9` , { method : 'GET' } ) ;
1289
+ const body = await res . json ( ) ;
1290
+
1291
+ expect ( res . status ) . toBe ( 200 ) ;
1292
+ expect ( body ) . toEqual ( { result : 10 } ) ;
1293
+ expect ( createContextMock ) . toHaveBeenCalledTimes ( 1 ) ;
1294
+ expect ( responseMetaMock ) . toHaveBeenCalledTimes ( 1 ) ;
1295
+ expect ( onErrorMock ) . toHaveBeenCalledTimes ( 0 ) ;
1296
+ }
1254
1297
1255
1298
close ( ) ;
1256
1299
} ) ;
0 commit comments