2
2
import aspida from '@aspida/axios' ;
3
3
import aspidaFetch from '@aspida/node-fetch' ;
4
4
import axios from 'axios' ;
5
- import { plainToInstance } from 'class-transformer' ;
6
- import { validateOrReject } from 'class-validator' ;
7
5
import express from 'express' ;
8
6
import FormData from 'form-data' ;
9
7
import fs from 'fs' ;
@@ -22,30 +20,13 @@ const client = api(aspida(undefined, { baseURL }));
22
20
const fetchClient = api ( aspidaFetch ( undefined , { baseURL : subBaseURL , throwHttpErrors : true } ) ) ;
23
21
let server : Server ;
24
22
let subServer : Server ;
25
- let subServerPlainToInstanceCallCount = 0 ;
26
- let subServerValidateOrRejectCallCount = 0 ;
27
23
28
24
beforeAll ( cb => {
29
25
server = frourio ( express ( ) ) . listen ( port , ( ) => {
30
- subServer = frourio ( express ( ) , {
31
- basePath : subBasePath ,
32
- plainToInstance : ( cls , object , options ) : object => {
33
- subServerPlainToInstanceCallCount ++ ;
34
- return plainToInstance ( cls , object , options ) ;
35
- } ,
36
- validateOrReject : ( instance , options ) : Promise < void > => {
37
- subServerValidateOrRejectCallCount ++ ;
38
- return validateOrReject ( instance , options ) ;
39
- } ,
40
- } ) . listen ( subPort , cb ) ;
26
+ subServer = frourio ( express ( ) , { basePath : subBasePath } ) . listen ( subPort , cb ) ;
41
27
} ) ;
42
28
} ) ;
43
29
44
- beforeEach ( ( ) => {
45
- subServerPlainToInstanceCallCount = 0 ;
46
- subServerValidateOrRejectCallCount = 0 ;
47
- } ) ;
48
-
49
30
afterAll ( cb => {
50
31
rimraf . sync ( 'servers/all/.upload' ) ;
51
32
server . close ( ( ) => {
@@ -167,9 +148,6 @@ test('PUT: JSON', async () => {
167
148
} ) ;
168
149
169
150
test ( 'POST: formdata' , async ( ) => {
170
- expect ( subServerPlainToInstanceCallCount ) . toBe ( 0 ) ;
171
- expect ( subServerValidateOrRejectCallCount ) . toBe ( 0 ) ;
172
-
173
151
const port = '3000' ;
174
152
const fileName = 'tsconfig.json' ;
175
153
@@ -184,9 +162,6 @@ test('POST: formdata', async () => {
184
162
expect ( res1 . data . port ) . toBe ( port ) ;
185
163
expect ( res1 . data . fileName ) . toBe ( fileName ) ;
186
164
187
- expect ( subServerPlainToInstanceCallCount ) . toBe ( 0 ) ;
188
- expect ( subServerValidateOrRejectCallCount ) . toBe ( 0 ) ;
189
-
190
165
const form2 = new FormData ( ) ;
191
166
const fileST2 = fs . createReadStream ( fileName ) ;
192
167
form2 . append ( 'port' , port ) ;
@@ -197,10 +172,6 @@ test('POST: formdata', async () => {
197
172
} ) ;
198
173
expect ( res2 . data . port ) . toBe ( port ) ;
199
174
expect ( res2 . data . fileName ) . toBe ( fileName ) ;
200
-
201
- // 2 = query + body
202
- expect ( subServerPlainToInstanceCallCount ) . toBe ( 2 ) ;
203
- expect ( subServerValidateOrRejectCallCount ) . toBe ( 2 ) ;
204
175
} ) ;
205
176
206
177
test ( 'PUT: zod validations' , async ( ) => {
@@ -260,9 +231,7 @@ test('POST: multi file upload', async () => {
260
231
form . append ( 'icon' , fileST ) ;
261
232
form . append ( 'files' , fileST ) ;
262
233
form . append ( 'files' , fileST ) ;
263
- const res = await axios . post ( `${ baseURL } /multiForm` , form , {
264
- headers : form . getHeaders ( ) ,
265
- } ) ;
234
+ const res = await axios . post ( `${ baseURL } /multiForm` , form , { headers : form . getHeaders ( ) } ) ;
266
235
267
236
expect ( res . data ) . toEqual ( {
268
237
requiredArr : 0 ,
@@ -280,12 +249,10 @@ test('POST: 400', async () => {
280
249
const fileST = fs . createReadStream ( fileName ) ;
281
250
form . append ( 'name' , 'sample' ) ;
282
251
form . append ( 'vals' , 'dammy' ) ;
283
- form . append ( 'icon ' , fileST ) ;
252
+ form . append ( 'files ' , fileST ) ;
284
253
285
254
await expect (
286
- axios . post ( `${ baseURL } /multiForm` , form , {
287
- headers : form . getHeaders ( ) ,
288
- } )
255
+ axios . post ( `${ baseURL } /multiForm` , form , { headers : form . getHeaders ( ) } )
289
256
) . rejects . toHaveProperty ( 'response.status' , 400 ) ;
290
257
} ) ;
291
258
@@ -294,10 +261,7 @@ test('POST: nested validation', async () => {
294
261
body : {
295
262
id : 123 ,
296
263
name : 'foo' ,
297
- location : {
298
- country : 'JP' ,
299
- stateProvince : 'Tokyo' ,
300
- } ,
264
+ location : { country : 'JP' , stateProvince : 'Tokyo' } ,
301
265
} ,
302
266
} ) ;
303
267
expect ( res1 . status ) . toBe ( 204 ) ;
@@ -310,10 +274,7 @@ test('POST: nested validation', async () => {
310
274
location : {
311
275
country : 'JP' ,
312
276
stateProvince : 'Tokyo' ,
313
- extra1 : {
314
- extra1a : 'bar' ,
315
- extra1b : 'baz' ,
316
- } ,
277
+ extra1 : { extra1a : 'bar' , extra1b : 'baz' } ,
317
278
} ,
318
279
extra2 : 'qux' ,
319
280
} as any ,
@@ -328,10 +289,7 @@ test('POST: 400 (nested validation)', async () => {
328
289
body : {
329
290
id : '123' ,
330
291
name : 'foo' ,
331
- location : {
332
- country : 'JP' ,
333
- stateProvince : 'Tokyo' ,
334
- } ,
292
+ location : { country : 'JP' , stateProvince : 'Tokyo' } ,
335
293
} as any ,
336
294
} )
337
295
) . rejects . toHaveProperty ( 'response.status' , 400 ) ;
@@ -349,10 +307,7 @@ test('POST: 400 (nested validation)', async () => {
349
307
body : {
350
308
id : 123 ,
351
309
name : 'foo' ,
352
- location : {
353
- country : 'XX' ,
354
- stateProvince : 'Tokyo' ,
355
- } ,
310
+ location : { country : 'JPN' , stateProvince : 'Tokyo' } ,
356
311
} as any ,
357
312
} )
358
313
) . rejects . toHaveProperty ( 'response.status' , 400 ) ;
@@ -363,10 +318,7 @@ test('POST: 400 (nested validation)', async () => {
363
318
body : {
364
319
id : 123 ,
365
320
name : 'foo' ,
366
- location : {
367
- country : 'JP' ,
368
- stateProvince : 1234 ,
369
- } ,
321
+ location : { country : 'JP' , stateProvince : 1234 } ,
370
322
} as any ,
371
323
} )
372
324
) . rejects . toHaveProperty ( 'response.status' , 400 ) ;
@@ -389,7 +341,7 @@ test('controller dependency injection', async () => {
389
341
} ) ) ( express ( ) ) ;
390
342
391
343
await expect (
392
- injectedController . get ( {
344
+ injectedController . get . handler ( {
393
345
query : {
394
346
id,
395
347
requiredNum : 1 ,
0 commit comments