1
1
import "reflect-metadata" ;
2
- import { createExpressServer , getMetadataArgsStorage } from " ../../src/index" ;
2
+ import { createExpressServer , getMetadataArgsStorage , createKoaServer } from ' ../../src/index' ;
3
3
import { ExpressMiddlewareInterface } from "../../src/driver/express/ExpressMiddlewareInterface" ;
4
4
import { Controller } from "../../src/decorator/Controller" ;
5
5
import { Get } from "../../src/decorator/Get" ;
@@ -10,10 +10,11 @@ import {NotAcceptableError} from "./../../src/http-error/NotAcceptableError";
10
10
import { ExpressErrorMiddlewareInterface } from "./../../src/driver/express/ExpressErrorMiddlewareInterface" ;
11
11
import { QueryParam } from '../../src/decorator/QueryParam' ;
12
12
import { OnUndefined } from '../../src/decorator/OnUndefined' ;
13
+ import { assertRequest } from './test-utils' ;
13
14
const chakram = require ( "chakram" ) ;
14
15
const expect = chakram . expect ;
15
16
16
- describe ( "express middlewares " , ( ) => {
17
+ describe ( "defaults " , ( ) => {
17
18
18
19
before ( ( ) => {
19
20
@@ -54,8 +55,9 @@ describe("express middlewares", () => {
54
55
55
56
let defaultUndefinedResultCode = 204 ;
56
57
let defaultNullResultCode = 404 ;
57
- let app : any ;
58
- before ( done => app = createExpressServer ( {
58
+ let expressApp : any ;
59
+ let kuaApp : any ;
60
+ before ( done => expressApp = createExpressServer ( {
59
61
defaults : {
60
62
nullResultCode : defaultNullResultCode ,
61
63
undefinedResultCode : defaultUndefinedResultCode ,
@@ -64,36 +66,52 @@ describe("express middlewares", () => {
64
66
}
65
67
}
66
68
} ) . listen ( 3001 , done ) ) ;
67
- after ( done => app . close ( done ) ) ;
68
-
69
- it ( "should return undefinedResultCode from defaults config for void function" , async ( ) => {
70
- let res = await chakram . get ( "http://127.0.0.1:3001/voidfunc" ) ;
71
- expect ( res ) . to . have . status ( defaultUndefinedResultCode ) ;
69
+ before ( done => kuaApp = createKoaServer ( {
70
+ defaults : {
71
+ nullResultCode : defaultNullResultCode ,
72
+ undefinedResultCode : defaultUndefinedResultCode ,
73
+ paramOptions : {
74
+ required : true
75
+ }
76
+ }
77
+ } ) . listen ( 3002 , done ) ) ;
78
+ after ( done => expressApp . close ( done ) ) ;
79
+ after ( done => kuaApp . close ( done ) ) ;
80
+
81
+ it ( "should return undefinedResultCode from defaults config for void function" , ( ) => {
82
+ assertRequest ( [ 3001 , 3002 ] , 'get' , 'voidfunc' , res => {
83
+ expect ( res ) . to . have . status ( defaultUndefinedResultCode ) ;
84
+ } ) ;
72
85
} ) ;
73
86
74
- it ( "should return undefinedResultCode from defaults config for promise void function" , async ( ) => {
75
- let res = await chakram . get ( "http://127.0.0.1:3001/promisevoidfunc" ) ;
76
- expect ( res ) . to . have . status ( defaultUndefinedResultCode ) ;
87
+ it ( "should return undefinedResultCode from defaults config for promise void function" , ( ) => {
88
+ assertRequest ( [ 3001 , 3002 ] , 'get' , 'promisevoidfunc' , res => {
89
+ expect ( res ) . to . have . status ( defaultUndefinedResultCode ) ;
90
+ } ) ;
77
91
} ) ;
78
92
79
- it ( "should return 400 from required paramOptions" , async ( ) => {
80
- let res = await chakram . get ( "http://127.0.0.1:3001/paramfunc" ) ;
81
- expect ( res ) . to . have . status ( 400 ) ;
93
+ it ( "should return 400 from required paramOptions" , ( ) => {
94
+ assertRequest ( [ 3001 , 3002 ] , 'get' , 'paramfunc' , res => {
95
+ expect ( res ) . to . have . status ( 400 ) ;
96
+ } ) ;
82
97
} ) ;
83
98
84
- it ( "should return nullResultCode from defaults config" , async ( ) => {
85
- let res = await chakram . get ( "http://127.0.0.1:3001/nullfunc" ) ;
86
- expect ( res ) . to . have . status ( defaultNullResultCode ) ;
99
+ it ( "should return nullResultCode from defaults config" , ( ) => {
100
+ assertRequest ( [ 3001 , 3002 ] , 'get' , 'nullfunc' , res => {
101
+ expect ( res ) . to . have . status ( defaultNullResultCode ) ;
102
+ } ) ;
87
103
} ) ;
88
104
89
- it ( "should return status code from OnUndefined annotation" , async ( ) => {
90
- let res = await chakram . get ( "http://127.0.0.1:3001/overridefunc" ) ;
91
- expect ( res ) . to . have . status ( 404 ) ;
105
+ it ( "should return status code from OnUndefined annotation" , ( ) => {
106
+ assertRequest ( [ 3001 , 3002 ] , 'get' , 'overridefunc' , res => {
107
+ expect ( res ) . to . have . status ( 404 ) ;
108
+ } ) ;
92
109
} ) ;
93
110
94
- it ( "should mark arg optional from QueryParam annotation" , async ( ) => {
95
- let res = await chakram . get ( "http://127.0.0.1:3001/overrideparamfunc" ) ;
96
- expect ( res ) . to . have . status ( 200 ) ;
111
+ it ( "should mark arg optional from QueryParam annotation" , ( ) => {
112
+ assertRequest ( [ 3001 , 3002 ] , 'get' , 'overrideparamfunc' , res => {
113
+ expect ( res ) . to . have . status ( 200 ) ;
114
+ } ) ;
97
115
} ) ;
98
116
99
117
} ) ;
0 commit comments