@@ -16,6 +16,7 @@ import {
1616 getSlackHandlers ,
1717 getSlackTestState ,
1818 resetSlackTestState ,
19+ runSlackHandlerWithDispatch ,
1920 startSlackMonitor as startSlackMonitorUntracked ,
2021 stopSlackMonitor ,
2122 useSlackStartupAuthClientOnce ,
@@ -375,7 +376,7 @@ describe("auth.test boot call", () => {
375376 expect ( getSlackInstallationKind ( "default" ) ) . toBe ( "enterprise" ) ;
376377
377378 const handler = await getSlackHandlerOrThrow ( "message" ) ;
378- await handler ( {
379+ await runSlackHandlerWithDispatch ( handler , {
379380 event : {
380381 type : "message" ,
381382 user : "UOTHER123" ,
@@ -394,7 +395,17 @@ describe("auth.test boot call", () => {
394395 } ) ;
395396
396397 expect ( replyMock ) . toHaveBeenCalledTimes ( 1 ) ;
397- await vi . waitFor ( ( ) => expect ( sendMock ) . toHaveBeenCalledTimes ( 1 ) ) ;
398+ const dispatchedContext = replyMock . mock . calls [ 0 ] ?. [ 0 ] ;
399+ expect ( dispatchedContext ) . toMatchObject ( {
400+ Body : expect . stringMatching ( / < @ U E N T E R P R I S E > .* s t a t u s / u) ,
401+ ChatType : "channel" ,
402+ WasMentioned : true ,
403+ } ) ;
404+ expect ( sendMock ) . toHaveBeenCalledWith (
405+ "channel:C12345678" ,
406+ "identity preserved" ,
407+ expect . any ( Object ) ,
408+ ) ;
398409 await expect ( stopSlackMonitor ( monitor ) ) . resolves . toBeUndefined ( ) ;
399410 expect ( getSlackInstallationKind ( "default" ) ) . toBeUndefined ( ) ;
400411 } ) ;
@@ -477,7 +488,8 @@ describe("presence polling transport", () => {
477488 ...options ,
478489 env : options . env ?? process . env ,
479490 } ) ;
480- getSlackTestState ( ) . replyMock . mockResolvedValue ( { text : "ok" } ) ;
491+ const { replyMock, sendMock } = getSlackTestState ( ) ;
492+ replyMock . mockResolvedValue ( { text : "ok" } ) ;
481493
482494 const nativeSetInterval = globalThis . setInterval ;
483495 let triggerPresencePoll : ( ( ) => void ) | undefined ;
@@ -496,7 +508,7 @@ describe("presence polling transport", () => {
496508 const monitor = startSlackMonitor ( monitorSlackProvider ) ;
497509 try {
498510 const handler = await getSlackHandlerOrThrow ( "message" ) ;
499- await handler ( {
511+ await runSlackHandlerWithDispatch ( handler , {
500512 event : {
501513 type : "message" ,
502514 user : "U_STALLED" ,
@@ -508,6 +520,15 @@ describe("presence polling transport", () => {
508520 context : { botUserId : "bot-user" } ,
509521 body : { } ,
510522 } ) ;
523+ const dispatchedContext = replyMock . mock . calls [ 0 ] ?. [ 0 ] ;
524+ expect ( dispatchedContext ) . toMatchObject ( {
525+ Body : expect . stringMatching (
526+ / A d a : h e l l o \n \[ s l a c k m e s s a g e i d : 1 0 0 \. 0 0 0 c h a n n e l : D _ S T A L L E D \] $ / u,
527+ ) ,
528+ ChatType : "direct" ,
529+ WasMentioned : false ,
530+ } ) ;
531+ expect ( sendMock ) . toHaveBeenCalledWith ( "channel:D_STALLED" , "ok" , expect . any ( Object ) ) ;
511532 expect ( triggerPresencePoll ) . toBeTypeOf ( "function" ) ;
512533 triggerPresencePoll ?.( ) ;
513534 await vi . waitFor ( ( ) => expect ( server . requestCount ) . toBe ( 1 ) , { timeout : 1_000 } ) ;
@@ -621,7 +642,7 @@ describe("user identity provider transport", () => {
621642 const monitor = await startWithoutBotToken ( config ) ;
622643 const handler = await getSlackHandlerOrThrow ( "message" ) ;
623644
624- await handler ( {
645+ await runSlackHandlerWithDispatch ( handler , {
625646 event : {
626647 type : "message" ,
627648 user : "U_OTHER" ,
@@ -634,7 +655,13 @@ describe("user identity provider transport", () => {
634655 body : { } ,
635656 } ) ;
636657
637- await vi . waitFor ( ( ) => expect ( sendMock ) . toHaveBeenCalledTimes ( 1 ) ) ;
658+ const dispatchedContext = replyMock . mock . calls [ 0 ] ?. [ 0 ] ;
659+ expect ( dispatchedContext ) . toMatchObject ( {
660+ Body : expect . stringMatching ( / < @ U _ S E L F > .* s t a t u s / u) ,
661+ ChatType : "channel" ,
662+ WasMentioned : true ,
663+ } ) ;
664+ expect ( sendMock ) . toHaveBeenCalledWith ( "channel:C1" , "acknowledged" , expect . any ( Object ) ) ;
638665 await stopSlackMonitor ( monitor ) ;
639666 } ) ;
640667
@@ -658,12 +685,18 @@ describe("user identity provider transport", () => {
658685 text : "hello" ,
659686 } ;
660687
661- await handler ( {
688+ await runSlackHandlerWithDispatch ( handler , {
662689 event : { ...baseEvent , user : "U_OTHER" , ts : "100.000" } ,
663690 context : { botUserId : "U_SELF" } ,
664691 body : { } ,
665692 } ) ;
666- await vi . waitFor ( ( ) => expect ( sendMock ) . toHaveBeenCalledTimes ( 1 ) ) ;
693+ const dispatchedContext = replyMock . mock . calls [ 0 ] ?. [ 0 ] ;
694+ expect ( dispatchedContext ) . toMatchObject ( {
695+ Body : expect . stringMatching ( / A d a : h e l l o \n \[ s l a c k m e s s a g e i d : 1 0 0 \. 0 0 0 c h a n n e l : D 1 \] $ / u) ,
696+ ChatType : "direct" ,
697+ WasMentioned : false ,
698+ } ) ;
699+ expect ( sendMock ) . toHaveBeenCalledWith ( "channel:D1" , "hello back" , expect . any ( Object ) ) ;
667700
668701 await handler ( {
669702 event : { ...baseEvent , user : "U_SELF" , ts : "101.000" } ,
@@ -948,7 +981,7 @@ describe("connected identity health", () => {
948981 } ) ;
949982 expect ( getSlackHandlers ( ) . has ( "reaction_added" ) ) . toBe ( true ) ;
950983
951- await handler ( {
984+ await runSlackHandlerWithDispatch ( handler , {
952985 event : {
953986 type : "message" ,
954987 user : "UOTHER123" ,
@@ -970,7 +1003,12 @@ describe("connected identity health", () => {
9701003 expect . objectContaining ( { channel : "C12345678" } ) ,
9711004 ) ;
9721005 expect ( replyMock ) . toHaveBeenCalledTimes ( 1 ) ;
973- await vi . waitFor ( ( ) => expect ( sendMock ) . toHaveBeenCalledTimes ( 1 ) ) ;
1006+ const dispatchedContext = replyMock . mock . calls [ 0 ] ?. [ 0 ] ;
1007+ expect ( dispatchedContext ) . toMatchObject ( {
1008+ Body : expect . stringMatching ( / < @ U E N T E R P R I S E > .* s t a t u s / u) ,
1009+ ChatType : "channel" ,
1010+ WasMentioned : true ,
1011+ } ) ;
9741012 expect ( sendMock ) . toHaveBeenCalledWith (
9751013 "channel:C12345678" ,
9761014 "identity restored" ,
0 commit comments