@@ -9,6 +9,8 @@ import {RoutingControllersOptions} from "../../src/RoutingControllersOptions";
99const chakram = require ( "chakram" ) ;
1010const expect = chakram . expect ;
1111
12+ const sleep = ( time : number ) => new Promise ( resolve => setTimeout ( resolve , time ) ) ;
13+
1214describe ( "Controller responds with value when Authorization succeeds (async)" , function ( ) {
1315
1416 before ( ( ) => {
@@ -31,11 +33,19 @@ describe("Controller responds with value when Authorization succeeds (async)", f
3133 return { test : "auth2" } ;
3234 }
3335
36+ @Authorized ( )
37+ @Get ( "/auth3" )
38+ async auth3 ( ) {
39+ await sleep ( 10 ) ;
40+ return { test : "auth3" } ;
41+ }
42+
3443 }
3544 } ) ;
3645
3746 const serverOptions : RoutingControllersOptions = {
3847 authorizationChecker : async ( action : Action , roles ?: string [ ] ) => {
48+ await sleep ( 10 ) ;
3949 return true ;
4050 }
4151 } ;
@@ -68,6 +78,13 @@ describe("Controller responds with value when Authorization succeeds (async)", f
6878 } ) ;
6979 } ) ;
7080
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+
7188} ) ;
7289
7390describe ( "Controller responds with value when Authorization succeeds (sync)" , function ( ) {
@@ -92,6 +109,13 @@ describe("Controller responds with value when Authorization succeeds (sync)", fu
92109 return { test : "auth2" } ;
93110 }
94111
112+ @Authorized ( )
113+ @Get ( "/auth3" )
114+ async auth3 ( ) {
115+ await sleep ( 10 ) ;
116+ return { test : "auth3" } ;
117+ }
118+
95119 }
96120 } ) ;
97121
@@ -129,6 +153,13 @@ describe("Controller responds with value when Authorization succeeds (sync)", fu
129153 } ) ;
130154 } ) ;
131155
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+
132163} ) ;
133164
134165describe ( "Authorized Decorators Http Status Code" , function ( ) {
0 commit comments