@@ -17,6 +17,7 @@ const { EventProcessingStatus } = require("../src/constants");
17
17
const { checkAndInsertPeriodicEvents } = require ( "../src/periodicEvents" ) ;
18
18
const { getOpenQueueEntries } = require ( "../src/runner/openEvents" ) ;
19
19
const EventQueueGenericOutboxHandler = require ( "../src/outbox/EventQueueGenericOutboxHandler" ) ;
20
+ const { getEnvInstance } = require ( "../src/shared/env" ) ;
20
21
21
22
const CUSTOM_HOOKS_SRV = "OutboxCustomHooks" ;
22
23
@@ -56,6 +57,28 @@ cds.env.requires.OutboxCustomHooks = {
56
57
} ,
57
58
} ;
58
59
60
+ cds . env . requires . AppNames = {
61
+ impl : "./outboxProject/srv/service/serviceAppNames.js" ,
62
+ outbox : {
63
+ kind : "persistent-outbox" ,
64
+ checkForNextChunk : false ,
65
+ events : {
66
+ appNamesString : {
67
+ appNames : [ ] ,
68
+ } ,
69
+ appNamesRegex : {
70
+ appNames : [ "/srv-backend.*/i" ] ,
71
+ } ,
72
+ appNamesMixStringMatch : {
73
+ appNames : [ "/srv-backend.*/i" , "a-srv-backend" ] ,
74
+ } ,
75
+ appNamesMixRegexMatch : {
76
+ appNames : [ "/a-srv-backend.*/i" , "srv-backend" ] ,
77
+ } ,
78
+ } ,
79
+ } ,
80
+ } ;
81
+
59
82
cds . env . requires . StandardService = {
60
83
impl : "./outboxProject/srv/service/standard-service.js" ,
61
84
outbox : {
@@ -1401,6 +1424,77 @@ describe("event-queue outbox", () => {
1401
1424
} ) ;
1402
1425
} ) ;
1403
1426
} ) ;
1427
+
1428
+ describe ( "app names" , ( ) => {
1429
+ let env = getEnvInstance ( ) ;
1430
+ beforeEach ( ( ) => {
1431
+ env . vcapApplication = { } ;
1432
+ } ) ;
1433
+
1434
+ it ( "regex - no match" , async ( ) => {
1435
+ const service = ( await cds . connect . to ( "AppNames" ) ) . tx ( context ) ;
1436
+ const data = { to : "to" } ;
1437
+ await service . send ( "appNamesRegex" , data ) ;
1438
+ await commitAndOpenNew ( ) ;
1439
+ await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
1440
+ await processEventQueue ( tx . context , "CAP_OUTBOX" , "AppNames.appNamesRegex" ) ;
1441
+ await commitAndOpenNew ( ) ;
1442
+ await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
1443
+ expect ( loggerMock . callsLengths ( ) . error ) . toEqual ( 0 ) ;
1444
+ } ) ;
1445
+
1446
+ it ( "regex - match" , async ( ) => {
1447
+ const service = ( await cds . connect . to ( "AppNames" ) ) . tx ( context ) ;
1448
+ env . vcapApplication = { application_name : `srv-backend-${ cds . utils . uuid ( ) } ` } ;
1449
+ const data = { to : "to" } ;
1450
+ await service . send ( "appNamesRegex" , data ) ;
1451
+ await commitAndOpenNew ( ) ;
1452
+ await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
1453
+ await processEventQueue ( tx . context , "CAP_OUTBOX" , "AppNames.appNamesRegex" ) ;
1454
+ await commitAndOpenNew ( ) ;
1455
+ await testHelper . selectEventQueueAndExpectDone ( tx , { expectedLength : 1 } ) ;
1456
+ expect ( loggerMock . callsLengths ( ) . error ) . toEqual ( 0 ) ;
1457
+ } ) ;
1458
+
1459
+ it ( "mix - regex no match - string match" , async ( ) => {
1460
+ const service = ( await cds . connect . to ( "AppNames" ) ) . tx ( context ) ;
1461
+ env . vcapApplication = { application_name : `a-srv-backend` } ;
1462
+ const data = { to : "to" } ;
1463
+ await service . send ( "appNamesMixStringMatch" , data ) ;
1464
+ await commitAndOpenNew ( ) ;
1465
+ await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
1466
+ await processEventQueue ( tx . context , "CAP_OUTBOX" , "AppNames.appNamesMixStringMatch" ) ;
1467
+ await commitAndOpenNew ( ) ;
1468
+ await testHelper . selectEventQueueAndExpectDone ( tx , { expectedLength : 1 } ) ;
1469
+ expect ( loggerMock . callsLengths ( ) . error ) . toEqual ( 0 ) ;
1470
+ } ) ;
1471
+
1472
+ it ( "mix - regex match - string no match" , async ( ) => {
1473
+ const service = ( await cds . connect . to ( "AppNames" ) ) . tx ( context ) ;
1474
+ env . vcapApplication = { application_name : `a-srv-backend-${ cds . utils . uuid ( ) } ` } ;
1475
+ const data = { to : "to" } ;
1476
+ await service . send ( "appNamesMixRegexMatch" , data ) ;
1477
+ await commitAndOpenNew ( ) ;
1478
+ await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
1479
+ await processEventQueue ( tx . context , "CAP_OUTBOX" , "AppNames.appNamesMixRegexMatch" ) ;
1480
+ await commitAndOpenNew ( ) ;
1481
+ await testHelper . selectEventQueueAndExpectDone ( tx , { expectedLength : 1 } ) ;
1482
+ expect ( loggerMock . callsLengths ( ) . error ) . toEqual ( 0 ) ;
1483
+ } ) ;
1484
+
1485
+ it ( "mix - regex no match - string no match" , async ( ) => {
1486
+ const service = ( await cds . connect . to ( "AppNames" ) ) . tx ( context ) ;
1487
+ env . vcapApplication = { application_name : `srv--backend` } ;
1488
+ const data = { to : "to" } ;
1489
+ await service . send ( "appNamesMixStringMatch" , data ) ;
1490
+ await commitAndOpenNew ( ) ;
1491
+ await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
1492
+ await processEventQueue ( tx . context , "CAP_OUTBOX" , "AppNames.appNamesMixStringMatch" ) ;
1493
+ await commitAndOpenNew ( ) ;
1494
+ await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
1495
+ expect ( loggerMock . callsLengths ( ) . error ) . toEqual ( 0 ) ;
1496
+ } ) ;
1497
+ } ) ;
1404
1498
} ) ;
1405
1499
1406
1500
const commitAndOpenNew = async ( ) => {
0 commit comments