@@ -306,4 +306,128 @@ describe('ServerRMQ', () => {
306
306
expect ( nack . calledWith ( message , false , false ) ) . not . to . be . true ;
307
307
} ) ;
308
308
} ) ;
309
+
310
+ describe ( 'matchRmqPattern' , ( ) => {
311
+ let matchRmqPattern : ( pattern : string , routingKey : string ) => boolean ;
312
+
313
+ beforeEach ( ( ) => {
314
+ matchRmqPattern = untypedServer . matchRmqPattern . bind ( untypedServer ) ;
315
+ } ) ;
316
+
317
+ describe ( 'exact matches' , ( ) => {
318
+ it ( 'should match identical patterns' , ( ) => {
319
+ expect ( matchRmqPattern ( 'user.created' , 'user.created' ) ) . to . be . true ;
320
+ expect ( matchRmqPattern ( 'order.updated' , 'order.updated' ) ) . to . be . true ;
321
+ } ) ;
322
+
323
+ it ( 'should not match different patterns' , ( ) => {
324
+ expect ( matchRmqPattern ( 'user.created' , 'user.updated' ) ) . to . be . false ;
325
+ expect ( matchRmqPattern ( 'order.created' , 'user.created' ) ) . to . be . false ;
326
+ } ) ;
327
+
328
+ it ( 'should handle patterns with $ character (original issue)' , ( ) => {
329
+ expect (
330
+ matchRmqPattern ( '$internal.plugin.status' , '$internal.plugin.status' ) ,
331
+ ) . to . be . true ;
332
+ expect (
333
+ matchRmqPattern (
334
+ '$internal.plugin.0.status' ,
335
+ '$internal.plugin.0.status' ,
336
+ ) ,
337
+ ) . to . be . true ;
338
+ expect ( matchRmqPattern ( 'user.$special.event' , 'user.$special.event' ) ) . to
339
+ . be . true ;
340
+ } ) ;
341
+ } ) ;
342
+
343
+ describe ( 'single wildcard (*)' , ( ) => {
344
+ it ( 'should match single segments' , ( ) => {
345
+ expect ( matchRmqPattern ( 'user.*' , 'user.created' ) ) . to . be . true ;
346
+ expect ( matchRmqPattern ( 'user.*' , 'user.updated' ) ) . to . be . true ;
347
+ expect ( matchRmqPattern ( '*.created' , 'user.created' ) ) . to . be . true ;
348
+ expect ( matchRmqPattern ( '*.created' , 'order.created' ) ) . to . be . true ;
349
+ } ) ;
350
+
351
+ it ( 'should not match when segment counts differ' , ( ) => {
352
+ expect ( matchRmqPattern ( 'user.*' , 'user.profile.created' ) ) . to . be . false ;
353
+ expect ( matchRmqPattern ( '*.created' , 'user.profile.created' ) ) . to . be
354
+ . false ;
355
+ } ) ;
356
+
357
+ it ( 'should handle patterns with $ and *' , ( ) => {
358
+ expect (
359
+ matchRmqPattern (
360
+ '$internal.plugin.*.status' ,
361
+ '$internal.plugin.0.status' ,
362
+ ) ,
363
+ ) . to . be . true ;
364
+ expect (
365
+ matchRmqPattern (
366
+ '$internal.plugin.*.status' ,
367
+ '$internal.plugin.1.status' ,
368
+ ) ,
369
+ ) . to . be . true ;
370
+ expect ( matchRmqPattern ( '$internal.*.status' , '$internal.plugin.status' ) )
371
+ . to . be . true ;
372
+ } ) ;
373
+
374
+ it ( 'should handle multiple * wildcards' , ( ) => {
375
+ expect ( matchRmqPattern ( '*.*.created' , 'user.profile.created' ) ) . to . be
376
+ . true ;
377
+ expect ( matchRmqPattern ( '*.*.created' , 'order.item.created' ) ) . to . be . true ;
378
+ expect ( matchRmqPattern ( '*.*.created' , 'user.created' ) ) . to . be . false ;
379
+ } ) ;
380
+ } ) ;
381
+
382
+ describe ( 'catch all wildcard (#)' , ( ) => {
383
+ it ( 'should match when # is at the end' , ( ) => {
384
+ expect ( matchRmqPattern ( 'user.#' , 'user.created' ) ) . to . be . true ;
385
+ expect ( matchRmqPattern ( 'user.#' , 'user.profile.created' ) ) . to . be . true ;
386
+ expect ( matchRmqPattern ( 'user.#' , 'user.profile.details.updated' ) ) . to . be
387
+ . true ;
388
+ } ) ;
389
+
390
+ it ( 'should handle patterns with $ and #' , ( ) => {
391
+ expect ( matchRmqPattern ( '$internal.#' , '$internal.plugin.status' ) ) . to . be
392
+ . true ;
393
+ expect ( matchRmqPattern ( '$internal.#' , '$internal.plugin.0.status' ) ) . to
394
+ . be . true ;
395
+ expect (
396
+ matchRmqPattern ( '$internal.plugin.#' , '$internal.plugin.0.status' ) ,
397
+ ) . to . be . true ;
398
+ } ) ;
399
+
400
+ it ( 'should handle # at the beginning' , ( ) => {
401
+ expect ( matchRmqPattern ( '#' , 'user.created' ) ) . to . be . true ;
402
+ expect ( matchRmqPattern ( '#' , 'user.profile.created' ) ) . to . be . true ;
403
+ expect ( matchRmqPattern ( '#' , 'created' ) ) . to . be . true ;
404
+ } ) ;
405
+ } ) ;
406
+
407
+ describe ( 'edge cases' , ( ) => {
408
+ it ( 'should handle empty routing key' , ( ) => {
409
+ expect ( matchRmqPattern ( 'user.created' , '' ) ) . to . be . false ;
410
+ expect ( matchRmqPattern ( '*' , '' ) ) . to . be . false ;
411
+ expect ( matchRmqPattern ( '#' , '' ) ) . to . be . true ;
412
+ } ) ;
413
+
414
+ it ( 'should handle single segments' , ( ) => {
415
+ expect ( matchRmqPattern ( 'user' , 'user' ) ) . to . be . true ;
416
+ expect ( matchRmqPattern ( '*' , 'user' ) ) . to . be . true ;
417
+ expect ( matchRmqPattern ( '#' , 'user' ) ) . to . be . true ;
418
+ } ) ;
419
+
420
+ it ( 'should handle complex $ patterns that previously failed' , ( ) => {
421
+ expect (
422
+ matchRmqPattern (
423
+ '$exchange.*.routing.#' ,
424
+ '$exchange.topic.routing.key.test' ,
425
+ ) ,
426
+ ) . to . be . true ;
427
+ expect ( matchRmqPattern ( '$sys.#' , '$sys.broker.clients' ) ) . to . be . true ;
428
+ expect ( matchRmqPattern ( '$SYS.#' , '$SYS.broker.load.messages.received' ) )
429
+ . to . be . true ;
430
+ } ) ;
431
+ } ) ;
432
+ } ) ;
309
433
} ) ;
0 commit comments