22import aspida from '@aspida/axios' ;
33import aspidaFetch from '@aspida/node-fetch' ;
44import axios from 'axios' ;
5- import { plainToInstance } from 'class-transformer' ;
6- import { validateOrReject } from 'class-validator' ;
75import fastify , { FastifyInstance } from 'fastify' ;
86import FormData from 'form-data' ;
97import fs from 'fs' ;
@@ -20,27 +18,14 @@ const client = api(aspida(undefined, { baseURL }));
2018const fetchClient = api ( aspidaFetch ( undefined , { baseURL : subBaseURL , throwHttpErrors : true } ) ) ;
2119let server : FastifyInstance ;
2220let subServer : FastifyInstance ;
23- let subServerPlainToInstanceCallCount = 0 ;
24- let subServerValidateOrRejectCallCount = 0 ;
2521
2622beforeEach ( ( ) => {
2723 server = fastify ( ) ;
2824 subServer = fastify ( ) ;
29- subServerPlainToInstanceCallCount = 0 ;
30- subServerValidateOrRejectCallCount = 0 ;
25+
3126 return Promise . all ( [
3227 frourio ( server ) . listen ( { port } ) ,
33- frourio ( subServer , {
34- basePath : subBasePath ,
35- plainToInstance : ( cls , object , options ) : object => {
36- subServerPlainToInstanceCallCount ++ ;
37- return plainToInstance ( cls , object , options ) ;
38- } ,
39- validateOrReject : ( instance , options ) : Promise < void > => {
40- subServerValidateOrRejectCallCount ++ ;
41- return validateOrReject ( instance , options ) ;
42- } ,
43- } ) . listen ( { port : subPort } ) ,
28+ frourio ( subServer , { basePath : subBasePath } ) . listen ( { port : subPort } ) ,
4429 ] ) ;
4530} ) ;
4631
@@ -160,9 +145,6 @@ test('PUT: JSON', async () => {
160145} ) ;
161146
162147test ( 'POST: formdata' , async ( ) => {
163- expect ( subServerPlainToInstanceCallCount ) . toBe ( 0 ) ;
164- expect ( subServerValidateOrRejectCallCount ) . toBe ( 0 ) ;
165-
166148 const port = '3000' ;
167149 const fileName = 'tsconfig.json' ;
168150
@@ -174,12 +156,10 @@ test('POST: formdata', async () => {
174156 params : { requiredNum : 0 , id : '1' , disable : 'true' , bool : false } ,
175157 headers : form1 . getHeaders ( ) ,
176158 } ) ;
159+
177160 expect ( res1 . data . port ) . toBe ( port ) ;
178161 expect ( res1 . data . fileName ) . toBe ( fileName ) ;
179162
180- expect ( subServerPlainToInstanceCallCount ) . toBe ( 0 ) ;
181- expect ( subServerValidateOrRejectCallCount ) . toBe ( 0 ) ;
182-
183163 const form2 = new FormData ( ) ;
184164 const fileST2 = fs . createReadStream ( fileName ) ;
185165 form2 . append ( 'port' , port ) ;
@@ -190,10 +170,6 @@ test('POST: formdata', async () => {
190170 } ) ;
191171 expect ( res2 . data . port ) . toBe ( port ) ;
192172 expect ( res2 . data . fileName ) . toBe ( fileName ) ;
193-
194- // 2 = query + body
195- expect ( subServerPlainToInstanceCallCount ) . toBe ( 2 ) ;
196- expect ( subServerValidateOrRejectCallCount ) . toBe ( 2 ) ;
197173} ) ;
198174
199175test ( 'PUT: zod validations' , async ( ) => {
@@ -273,12 +249,10 @@ test('POST: 400', async () => {
273249 const fileST = fs . createReadStream ( fileName ) ;
274250 form . append ( 'name' , 'sample' ) ;
275251 form . append ( 'vals' , 'dammy' ) ;
276- form . append ( 'icon ' , fileST ) ;
252+ form . append ( 'files ' , fileST ) ;
277253
278254 await expect (
279- axios . post ( `${ baseURL } /multiForm` , form , {
280- headers : form . getHeaders ( ) ,
281- } )
255+ axios . post ( `${ baseURL } /multiForm` , form , { headers : form . getHeaders ( ) } )
282256 ) . rejects . toHaveProperty ( 'response.status' , 400 ) ;
283257} ) ;
284258
@@ -287,10 +261,7 @@ test('POST: nested validation', async () => {
287261 body : {
288262 id : 123 ,
289263 name : 'foo' ,
290- location : {
291- country : 'JP' ,
292- stateProvince : 'Tokyo' ,
293- } ,
264+ location : { country : 'JP' , stateProvince : 'Tokyo' } ,
294265 } ,
295266 } ) ;
296267 expect ( res1 . status ) . toBe ( 204 ) ;
@@ -303,10 +274,7 @@ test('POST: nested validation', async () => {
303274 location : {
304275 country : 'JP' ,
305276 stateProvince : 'Tokyo' ,
306- extra1 : {
307- extra1a : 'bar' ,
308- extra1b : 'baz' ,
309- } ,
277+ extra1 : { extra1a : 'bar' , extra1b : 'baz' } ,
310278 } ,
311279 extra2 : 'qux' ,
312280 } as any ,
@@ -321,10 +289,7 @@ test('POST: 400 (nested validation)', async () => {
321289 body : {
322290 id : '123' ,
323291 name : 'foo' ,
324- location : {
325- country : 'JP' ,
326- stateProvince : 'Tokyo' ,
327- } ,
292+ location : { country : 'JP' , stateProvince : 'Tokyo' } ,
328293 } as any ,
329294 } )
330295 ) . rejects . toHaveProperty ( 'response.status' , 400 ) ;
@@ -342,10 +307,7 @@ test('POST: 400 (nested validation)', async () => {
342307 body : {
343308 id : 123 ,
344309 name : 'foo' ,
345- location : {
346- country : 'XX' ,
347- stateProvince : 'Tokyo' ,
348- } ,
310+ location : { country : 'JPN' , stateProvince : 'Tokyo' } ,
349311 } as any ,
350312 } )
351313 ) . rejects . toHaveProperty ( 'response.status' , 400 ) ;
@@ -356,10 +318,7 @@ test('POST: 400 (nested validation)', async () => {
356318 body : {
357319 id : 123 ,
358320 name : 'foo' ,
359- location : {
360- country : 'JP' ,
361- stateProvince : 1234 ,
362- } ,
321+ location : { country : 'JP' , stateProvince : 1234 } ,
363322 } as any ,
364323 } )
365324 ) . rejects . toHaveProperty ( 'response.status' , 400 ) ;
@@ -382,7 +341,7 @@ test('controller dependency injection', async () => {
382341 } ) ) ( server ) ;
383342
384343 await expect (
385- injectedController . get ( {
344+ injectedController . get . handler ( {
386345 query : {
387346 id,
388347 requiredNum : 1 ,
0 commit comments