@@ -1374,3 +1374,81 @@ Deno.test("jetstream - jsm base timeout", async () => {
13741374
13751375 await cleanup ( ns , nc ) ;
13761376} ) ;
1377+
1378+ Deno . test ( "jetstream - watcherPrefix" , async ( ) => {
1379+ const { ns, nc } = await setup ( jetstreamServerConf ( { } ) ) ;
1380+
1381+ async function transitive ( js : JetStreamClient ) : Promise < void > {
1382+ const { watcherPrefix } = js . getOptions ( ) ;
1383+ const jsm = await js . jetstreamManager ( ) ;
1384+ assertEquals ( watcherPrefix , jsm . getOptions ( ) . watcherPrefix ) ;
1385+
1386+ const js2 = jsm . jetstream ( ) ;
1387+ assertEquals ( watcherPrefix , js2 . getOptions ( ) . watcherPrefix ) ;
1388+ }
1389+
1390+ let js = jetstream ( nc ) ;
1391+ assertEquals ( js . getOptions ( ) . watcherPrefix , undefined ) ;
1392+
1393+ const jsm = await jetstreamManager ( nc ) ;
1394+ assertEquals ( jsm . getOptions ( ) . watcherPrefix , undefined ) ;
1395+
1396+ const nc2 = await connect ( { port : ns . port , inboxPrefix : "hello" } ) ;
1397+ js = jetstream ( nc2 ) ;
1398+ assertEquals ( js . getOptions ( ) . watcherPrefix , "hello" ) ;
1399+ await transitive ( js ) ;
1400+
1401+ js = jetstream ( nc2 , { watcherPrefix : "bar" } ) ;
1402+ assertEquals ( js . getOptions ( ) . watcherPrefix , "bar" ) ;
1403+ await transitive ( js ) ;
1404+
1405+ assertThrows (
1406+ ( ) => {
1407+ jetstream ( nc2 , { watcherPrefix : "hello.*" } ) ;
1408+ } ,
1409+ Error ,
1410+ "'prefix' cannot have wildcards ('hello.*')" ,
1411+ ) ;
1412+
1413+ await assertRejects (
1414+ ( ) => {
1415+ return jetstreamManager ( nc , { watcherPrefix : "hello.*" } ) ;
1416+ } ,
1417+ Error ,
1418+ "'prefix' cannot have wildcards ('hello.*')" ,
1419+ ) ;
1420+
1421+ await cleanup ( ns , nc , nc2 ) ;
1422+ } ) ;
1423+
1424+ Deno . test ( "jetstream - watcher deliver_subject" , async ( ) => {
1425+ const { ns, nc } = await setup ( jetstreamServerConf ( { } ) ) ;
1426+
1427+ const jsm = await jetstreamManager ( nc ) ;
1428+ await jsm . streams . add ( { name : "A" , subjects : [ "a" ] } ) ;
1429+
1430+ async function assertDeliverTo (
1431+ js : JetStreamClient ,
1432+ deliverPrefix : string ,
1433+ ) : Promise < void > {
1434+ const pc = await js . consumers . getPushConsumer ( "A" ) ;
1435+ const { config : { deliver_subject } } = await pc . info ( true ) ;
1436+ assertEquals ( deliver_subject ?. split ( "." ) [ 0 ] , deliverPrefix ) ;
1437+ await pc . delete ( ) ;
1438+ }
1439+
1440+ // with no prefix, defaults to inbox
1441+ let js = jetstream ( nc ) ;
1442+ await assertDeliverTo ( js , "_INBOX" ) ;
1443+
1444+ // respects inboxPrefix
1445+ const nc2 = await connect ( { port : ns . port , inboxPrefix : "hallo" } ) ;
1446+ js = jetstream ( nc2 ) ;
1447+ await assertDeliverTo ( js , "hallo" ) ;
1448+
1449+ // override inboxPrefix
1450+ js = jetstream ( nc2 , { watcherPrefix : "hola" } ) ;
1451+ await assertDeliverTo ( js , "hola" ) ;
1452+
1453+ await cleanup ( ns , nc , nc2 ) ;
1454+ } ) ;
0 commit comments