@@ -17,7 +17,7 @@ describe('Middlewares', () => {
17
17
let httpServer : HttpServer ;
18
18
let wsApp : Server ;
19
19
let wsClient : Socket ;
20
- let testResult ;
20
+ let testResult : string [ ] = [ ] ;
21
21
let socketControllers : SocketControllers ;
22
22
23
23
beforeEach ( done => {
@@ -33,7 +33,7 @@ describe('Middlewares', () => {
33
33
} ) ;
34
34
35
35
afterEach ( ( ) => {
36
- testResult = undefined ;
36
+ testResult = [ ] ;
37
37
38
38
Container . reset ( ) ;
39
39
wsClient . close ( ) ;
@@ -53,7 +53,7 @@ describe('Middlewares', () => {
53
53
@Service ( )
54
54
class GlobalMiddleware implements MiddlewareInterface {
55
55
use ( socket : any , next : ( err ?: any ) => any ) : any {
56
- testResult = 'global middleware' ;
56
+ testResult . push ( 'global middleware' ) ;
57
57
next ( ) ;
58
58
}
59
59
}
@@ -76,7 +76,7 @@ describe('Middlewares', () => {
76
76
wsClient = io ( PATH_FOR_CLIENT , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
77
77
78
78
await waitForEvent ( wsClient , 'connected' ) ;
79
- expect ( testResult ) . toEqual ( 'global middleware' ) ;
79
+ expect ( testResult ) . toEqual ( [ 'global middleware' ] ) ;
80
80
} ) ;
81
81
82
82
describe ( 'string namespace' , ( ) => {
@@ -85,7 +85,16 @@ describe('Middlewares', () => {
85
85
@Service ( )
86
86
class StringNamespaceMiddleware implements MiddlewareInterface {
87
87
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' ) ;
89
98
next ( ) ;
90
99
}
91
100
}
@@ -102,21 +111,30 @@ describe('Middlewares', () => {
102
111
socketControllers = new SocketControllers ( {
103
112
io : wsApp ,
104
113
container : Container ,
105
- middlewares : [ StringNamespaceMiddleware ] ,
114
+ middlewares : [ StringNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
106
115
controllers : [ StringNamespaceController ] ,
107
116
} ) ;
108
117
wsClient = io ( PATH_FOR_CLIENT + '/string' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
109
118
110
119
await waitForEvent ( wsClient , 'connected' ) ;
111
- expect ( testResult ) . toEqual ( 'string middleware' ) ;
120
+ expect ( testResult ) . toEqual ( [ 'string middleware' , 'middleware without namespace' ] ) ;
112
121
} ) ;
113
122
114
123
it ( 'incorrect namespace' , async ( ) => {
115
124
@Middleware ( { namespace : '/string' } )
116
125
@Service ( )
117
126
class StringNamespaceMiddleware implements MiddlewareInterface {
118
127
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' ) ;
120
138
next ( ) ;
121
139
}
122
140
}
@@ -133,13 +151,13 @@ describe('Middlewares', () => {
133
151
socketControllers = new SocketControllers ( {
134
152
io : wsApp ,
135
153
container : Container ,
136
- middlewares : [ StringNamespaceMiddleware ] ,
154
+ middlewares : [ StringNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
137
155
controllers : [ String2NamespaceController ] ,
138
156
} ) ;
139
157
wsClient = io ( PATH_FOR_CLIENT + '/string2' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
140
158
141
159
await waitForEvent ( wsClient , 'connected' ) ;
142
- expect ( testResult ) . toEqual ( undefined ) ;
160
+ expect ( testResult ) . toEqual ( [ 'middleware without namespace' ] ) ;
143
161
} ) ;
144
162
} ) ;
145
163
@@ -149,7 +167,16 @@ describe('Middlewares', () => {
149
167
@Service ( )
150
168
class RegexpNamespaceMiddleware implements MiddlewareInterface {
151
169
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' ) ;
153
180
next ( ) ;
154
181
}
155
182
}
@@ -166,21 +193,30 @@ describe('Middlewares', () => {
166
193
socketControllers = new SocketControllers ( {
167
194
io : wsApp ,
168
195
container : Container ,
169
- middlewares : [ RegexpNamespaceMiddleware ] ,
196
+ middlewares : [ RegexpNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
170
197
controllers : [ RegexpNamespaceController ] ,
171
198
} ) ;
172
199
wsClient = io ( PATH_FOR_CLIENT + '/dynamic-1' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
173
200
174
201
await waitForEvent ( wsClient , 'connected' ) ;
175
- expect ( testResult ) . toEqual ( '/dynamic-1' ) ;
202
+ expect ( testResult ) . toEqual ( [ '/dynamic-1' , 'middleware without namespace' ] ) ;
176
203
} ) ;
177
204
178
205
it ( 'incorrect namespace' , async ( ) => {
179
206
@Middleware ( { namespace : / ^ \/ d y n a m i c - \s + $ / } )
180
207
@Service ( )
181
208
class RegexpNamespaceMiddleware implements MiddlewareInterface {
182
209
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' ) ;
184
220
next ( ) ;
185
221
}
186
222
}
@@ -197,13 +233,13 @@ describe('Middlewares', () => {
197
233
socketControllers = new SocketControllers ( {
198
234
io : wsApp ,
199
235
container : Container ,
200
- middlewares : [ RegexpNamespaceMiddleware ] ,
236
+ middlewares : [ RegexpNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
201
237
controllers : [ RegexpNamespaceController ] ,
202
238
} ) ;
203
239
wsClient = io ( PATH_FOR_CLIENT + '/dynamic-1' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
204
240
205
241
await waitForEvent ( wsClient , 'connected' ) ;
206
- expect ( testResult ) . toEqual ( undefined ) ;
242
+ expect ( testResult ) . toEqual ( [ 'middleware without namespace' ] ) ;
207
243
} ) ;
208
244
} ) ;
209
245
@@ -213,7 +249,16 @@ describe('Middlewares', () => {
213
249
@Service ( )
214
250
class RegexpArrayNamespaceMiddleware implements MiddlewareInterface {
215
251
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' ) ;
217
262
next ( ) ;
218
263
}
219
264
}
@@ -230,21 +275,30 @@ describe('Middlewares', () => {
230
275
socketControllers = new SocketControllers ( {
231
276
io : wsApp ,
232
277
container : Container ,
233
- middlewares : [ RegexpArrayNamespaceMiddleware ] ,
278
+ middlewares : [ RegexpArrayNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
234
279
controllers : [ RegexpNamespaceController ] ,
235
280
} ) ;
236
281
wsClient = io ( PATH_FOR_CLIENT + '/dynamic-1' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
237
282
238
283
await waitForEvent ( wsClient , 'connected' ) ;
239
- expect ( testResult ) . toEqual ( '/dynamic-1' ) ;
284
+ expect ( testResult ) . toEqual ( [ '/dynamic-1' , 'middleware without namespace' ] ) ;
240
285
} ) ;
241
286
242
287
it ( 'incorrect namespace' , async ( ) => {
243
288
@Middleware ( { namespace : [ / ^ \/ d y n a m i c - \s + $ / ] } )
244
289
@Service ( )
245
290
class RegexpArrayNamespaceMiddleware implements MiddlewareInterface {
246
291
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' ) ;
248
302
next ( ) ;
249
303
}
250
304
}
@@ -261,13 +315,13 @@ describe('Middlewares', () => {
261
315
socketControllers = new SocketControllers ( {
262
316
io : wsApp ,
263
317
container : Container ,
264
- middlewares : [ RegexpArrayNamespaceMiddleware ] ,
318
+ middlewares : [ RegexpArrayNamespaceMiddleware , MiddlewareWithoutNamespace ] ,
265
319
controllers : [ RegexpNamespaceController ] ,
266
320
} ) ;
267
321
wsClient = io ( PATH_FOR_CLIENT + '/dynamic-1' , { reconnection : false , timeout : 5000 , forceNew : true } ) ;
268
322
269
323
await waitForEvent ( wsClient , 'connected' ) ;
270
- expect ( testResult ) . toEqual ( undefined ) ;
324
+ expect ( testResult ) . toEqual ( [ 'middleware without namespace' ] ) ;
271
325
} ) ;
272
326
} ) ;
273
327
} ) ;
0 commit comments