@@ -9,6 +9,8 @@ import {RoutingControllersOptions} from "../../src/RoutingControllersOptions";
9
9
const chakram = require ( "chakram" ) ;
10
10
const expect = chakram . expect ;
11
11
12
+ const sleep = ( time : number ) => new Promise ( resolve => setTimeout ( resolve , time ) ) ;
13
+
12
14
describe ( "Controller responds with value when Authorization succeeds (async)" , function ( ) {
13
15
14
16
before ( ( ) => {
@@ -31,11 +33,19 @@ describe("Controller responds with value when Authorization succeeds (async)", f
31
33
return { test : "auth2" } ;
32
34
}
33
35
36
+ @Authorized ( )
37
+ @Get ( "/auth3" )
38
+ async auth3 ( ) {
39
+ await sleep ( 10 ) ;
40
+ return { test : "auth3" } ;
41
+ }
42
+
34
43
}
35
44
} ) ;
36
45
37
46
const serverOptions : RoutingControllersOptions = {
38
47
authorizationChecker : async ( action : Action , roles ?: string [ ] ) => {
48
+ await sleep ( 10 ) ;
39
49
return true ;
40
50
}
41
51
} ;
@@ -68,6 +78,13 @@ describe("Controller responds with value when Authorization succeeds (async)", f
68
78
} ) ;
69
79
} ) ;
70
80
81
+ describe ( "async" , ( ) => {
82
+ assertRequest ( [ 3001 , 3002 ] , "get" , "auth3" , response => {
83
+ expect ( response ) . to . have . status ( 200 ) ;
84
+ expect ( response . body ) . to . eql ( { test : "auth3" } ) ;
85
+ } ) ;
86
+ } ) ;
87
+
71
88
} ) ;
72
89
73
90
describe ( "Controller responds with value when Authorization succeeds (sync)" , function ( ) {
@@ -92,6 +109,13 @@ describe("Controller responds with value when Authorization succeeds (sync)", fu
92
109
return { test : "auth2" } ;
93
110
}
94
111
112
+ @Authorized ( )
113
+ @Get ( "/auth3" )
114
+ async auth3 ( ) {
115
+ await sleep ( 10 ) ;
116
+ return { test : "auth3" } ;
117
+ }
118
+
95
119
}
96
120
} ) ;
97
121
@@ -129,6 +153,13 @@ describe("Controller responds with value when Authorization succeeds (sync)", fu
129
153
} ) ;
130
154
} ) ;
131
155
156
+ describe ( "async" , ( ) => {
157
+ assertRequest ( [ 3001 , 3002 ] , "get" , "auth3" , response => {
158
+ expect ( response ) . to . have . status ( 200 ) ;
159
+ expect ( response . body ) . to . eql ( { test : "auth3" } ) ;
160
+ } ) ;
161
+ } ) ;
162
+
132
163
} ) ;
133
164
134
165
describe ( "Authorized Decorators Http Status Code" , function ( ) {
0 commit comments