@@ -17,7 +17,7 @@ describe('Middlewares', () => {
1717 let httpServer : HttpServer ;
1818 let wsApp : Server ;
1919 let wsClient : Socket ;
20- let testResult ;
20+ let testResult : string [ ] = [ ] ;
2121 let socketControllers : SocketControllers ;
2222
2323 beforeEach ( done => {
@@ -33,7 +33,7 @@ describe('Middlewares', () => {
3333 } ) ;
3434
3535 afterEach ( ( ) => {
36- testResult = undefined ;
36+ testResult = [ ] ;
3737
3838 Container . reset ( ) ;
3939 wsClient . close ( ) ;
@@ -53,7 +53,7 @@ describe('Middlewares', () => {
5353 @Service ( )
5454 class GlobalMiddleware implements MiddlewareInterface {
5555 use ( socket : any , next : ( err ?: any ) => any ) : any {
56- testResult = 'global middleware' ;
56+ testResult . push ( 'global middleware' ) ;
5757 next ( ) ;
5858 }
5959 }
@@ -76,7 +76,7 @@ describe('Middlewares', () => {
7676 wsClient = io ( PATH_FOR_CLIENT , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
7777
7878 await waitForEvent ( wsClient , 'connected' ) ;
79- expect ( testResult ) . toEqual ( 'global middleware' ) ;
79+ expect ( testResult ) . toEqual ( [ 'global middleware' ] ) ;
8080 } ) ;
8181
8282 describe ( 'string namespace' , ( ) => {
@@ -85,7 +85,16 @@ describe('Middlewares', () => {
8585 @Service ( )
8686 class StringNamespaceMiddleware implements MiddlewareInterface {
8787 use ( socket : any , next : ( err ?: any ) => any ) : any {
88- testResult = 'string middleware' ;
88+ testResult . push ( 'string middleware' ) ;
89+ next ( ) ;
90+ }
91+ }
92+
93+ @Middleware ( )
94+ @Service ( )
95+ class MiddlewareWithoutNamespace implements MiddlewareInterface {
96+ use ( socket : any , next : ( err ?: any ) => any ) : any {
97+ testResult . push ( 'middleware without namespace' ) ;
8998 next ( ) ;
9099 }
91100 }
@@ -102,21 +111,30 @@ describe('Middlewares', () => {
102111 socketControllers = new SocketControllers ( {
103112 io : wsApp ,
104113 container : Container ,
105- middlewares : [ StringNamespaceMiddleware ] ,
114+ middlewares : [ StringNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
106115 controllers : [ StringNamespaceController ] ,
107116 } ) ;
108117 wsClient = io ( PATH_FOR_CLIENT + '/string' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
109118
110119 await waitForEvent ( wsClient , 'connected' ) ;
111- expect ( testResult ) . toEqual ( 'string middleware' ) ;
120+ expect ( testResult ) . toEqual ( [ 'string middleware' , 'middleware without namespace' ] ) ;
112121 } ) ;
113122
114123 it ( 'incorrect namespace' , async ( ) => {
115124 @Middleware ( { namespace : '/string' } )
116125 @Service ( )
117126 class StringNamespaceMiddleware implements MiddlewareInterface {
118127 use ( socket : any , next : ( err ?: any ) => any ) : any {
119- testResult = 'string middleware' ;
128+ testResult . push ( 'string middleware' ) ;
129+ next ( ) ;
130+ }
131+ }
132+
133+ @Middleware ( )
134+ @Service ( )
135+ class MiddlewareWithoutNamespace implements MiddlewareInterface {
136+ use ( socket : any , next : ( err ?: any ) => any ) : any {
137+ testResult . push ( 'middleware without namespace' ) ;
120138 next ( ) ;
121139 }
122140 }
@@ -133,13 +151,13 @@ describe('Middlewares', () => {
133151 socketControllers = new SocketControllers ( {
134152 io : wsApp ,
135153 container : Container ,
136- middlewares : [ StringNamespaceMiddleware ] ,
154+ middlewares : [ StringNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
137155 controllers : [ String2NamespaceController ] ,
138156 } ) ;
139157 wsClient = io ( PATH_FOR_CLIENT + '/string2' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
140158
141159 await waitForEvent ( wsClient , 'connected' ) ;
142- expect ( testResult ) . toEqual ( undefined ) ;
160+ expect ( testResult ) . toEqual ( [ 'middleware without namespace' ] ) ;
143161 } ) ;
144162 } ) ;
145163
@@ -149,7 +167,16 @@ describe('Middlewares', () => {
149167 @Service ( )
150168 class RegexpNamespaceMiddleware implements MiddlewareInterface {
151169 use ( socket : any , next : ( err ?: any ) => any ) : any {
152- testResult = socket . nsp . name ;
170+ testResult . push ( socket . nsp . name as string ) ;
171+ next ( ) ;
172+ }
173+ }
174+
175+ @Middleware ( )
176+ @Service ( )
177+ class MiddlewareWithoutNamespace implements MiddlewareInterface {
178+ use ( socket : any , next : ( err ?: any ) => any ) : any {
179+ testResult . push ( 'middleware without namespace' ) ;
153180 next ( ) ;
154181 }
155182 }
@@ -166,21 +193,30 @@ describe('Middlewares', () => {
166193 socketControllers = new SocketControllers ( {
167194 io : wsApp ,
168195 container : Container ,
169- middlewares : [ RegexpNamespaceMiddleware ] ,
196+ middlewares : [ RegexpNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
170197 controllers : [ RegexpNamespaceController ] ,
171198 } ) ;
172199 wsClient = io ( PATH_FOR_CLIENT + '/dynamic-1' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
173200
174201 await waitForEvent ( wsClient , 'connected' ) ;
175- expect ( testResult ) . toEqual ( '/dynamic-1' ) ;
202+ expect ( testResult ) . toEqual ( [ '/dynamic-1' , 'middleware without namespace' ] ) ;
176203 } ) ;
177204
178205 it ( 'incorrect namespace' , async ( ) => {
179206 @Middleware ( { namespace : / ^ \/ d y n a m i c - \s + $ / } )
180207 @Service ( )
181208 class RegexpNamespaceMiddleware implements MiddlewareInterface {
182209 use ( socket : any , next : ( err ?: any ) => any ) : any {
183- testResult = socket . nsp . name ;
210+ testResult . push ( socket . nsp . name as string ) ;
211+ next ( ) ;
212+ }
213+ }
214+
215+ @Middleware ( )
216+ @Service ( )
217+ class MiddlewareWithoutNamespace implements MiddlewareInterface {
218+ use ( socket : any , next : ( err ?: any ) => any ) : any {
219+ testResult . push ( 'middleware without namespace' ) ;
184220 next ( ) ;
185221 }
186222 }
@@ -197,13 +233,13 @@ describe('Middlewares', () => {
197233 socketControllers = new SocketControllers ( {
198234 io : wsApp ,
199235 container : Container ,
200- middlewares : [ RegexpNamespaceMiddleware ] ,
236+ middlewares : [ RegexpNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
201237 controllers : [ RegexpNamespaceController ] ,
202238 } ) ;
203239 wsClient = io ( PATH_FOR_CLIENT + '/dynamic-1' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
204240
205241 await waitForEvent ( wsClient , 'connected' ) ;
206- expect ( testResult ) . toEqual ( undefined ) ;
242+ expect ( testResult ) . toEqual ( [ 'middleware without namespace' ] ) ;
207243 } ) ;
208244 } ) ;
209245
@@ -213,7 +249,16 @@ describe('Middlewares', () => {
213249 @Service ( )
214250 class RegexpArrayNamespaceMiddleware implements MiddlewareInterface {
215251 use ( socket : any , next : ( err ?: any ) => any ) : any {
216- testResult = socket . nsp . name ;
252+ testResult . push ( socket . nsp . name as string ) ;
253+ next ( ) ;
254+ }
255+ }
256+
257+ @Middleware ( )
258+ @Service ( )
259+ class MiddlewareWithoutNamespace implements MiddlewareInterface {
260+ use ( socket : any , next : ( err ?: any ) => any ) : any {
261+ testResult . push ( 'middleware without namespace' ) ;
217262 next ( ) ;
218263 }
219264 }
@@ -230,21 +275,30 @@ describe('Middlewares', () => {
230275 socketControllers = new SocketControllers ( {
231276 io : wsApp ,
232277 container : Container ,
233- middlewares : [ RegexpArrayNamespaceMiddleware ] ,
278+ middlewares : [ RegexpArrayNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
234279 controllers : [ RegexpNamespaceController ] ,
235280 } ) ;
236281 wsClient = io ( PATH_FOR_CLIENT + '/dynamic-1' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
237282
238283 await waitForEvent ( wsClient , 'connected' ) ;
239- expect ( testResult ) . toEqual ( '/dynamic-1' ) ;
284+ expect ( testResult ) . toEqual ( [ '/dynamic-1' , 'middleware without namespace' ] ) ;
240285 } ) ;
241286
242287 it ( 'incorrect namespace' , async ( ) => {
243288 @Middleware ( { namespace : [ / ^ \/ d y n a m i c - \s + $ / ] } )
244289 @Service ( )
245290 class RegexpArrayNamespaceMiddleware implements MiddlewareInterface {
246291 use ( socket : any , next : ( err ?: any ) => any ) : any {
247- testResult = socket . nsp . name ;
292+ testResult . push ( socket . nsp . name as string ) ;
293+ next ( ) ;
294+ }
295+ }
296+
297+ @Middleware ( )
298+ @Service ( )
299+ class MiddlewareWithoutNamespace implements MiddlewareInterface {
300+ use ( socket : any , next : ( err ?: any ) => any ) : any {
301+ testResult . push ( 'middleware without namespace' ) ;
248302 next ( ) ;
249303 }
250304 }
@@ -261,13 +315,13 @@ describe('Middlewares', () => {
261315 socketControllers = new SocketControllers ( {
262316 io : wsApp ,
263317 container : Container ,
264- middlewares : [ RegexpArrayNamespaceMiddleware ] ,
318+ middlewares : [ RegexpArrayNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
265319 controllers : [ RegexpNamespaceController ] ,
266320 } ) ;
267321 wsClient = io ( PATH_FOR_CLIENT + '/dynamic-1' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
268322
269323 await waitForEvent ( wsClient , 'connected' ) ;
270- expect ( testResult ) . toEqual ( undefined ) ;
324+ expect ( testResult ) . toEqual ( [ 'middleware without namespace' ] ) ;
271325 } ) ;
272326 } ) ;
273327} ) ;
0 commit comments