@@ -86,14 +86,15 @@ describe("outbound", () => {
8686
8787 function setupAccountContext ( params ?: {
8888 account ?: typeof mockAccount | null ;
89+ configured ?: boolean ;
8990 availableAccountIds ?: string [ ] ;
9091 } ) {
9192 const account = params ?. account === undefined ? mockAccount : params . account ;
9293 vi . mocked ( resolveTwitchAccountContext ) . mockImplementation ( ( _cfg , accountId ) => ( {
9394 accountId : accountId ?. trim ( ) || "default" ,
9495 account,
9596 tokenResolution : { source : "config" , token : account ?. accessToken ?? "" } ,
96- configured : account !== null ,
97+ configured : account ? ( params ?. configured ?? true ) : false ,
9798 availableAccountIds : params ?. availableAccountIds ?? [ "default" ] ,
9899 } ) ) ;
99100 }
@@ -148,7 +149,6 @@ describe("outbound", () => {
148149 setupAccountContext ( ) ;
149150 const receipt = twitchTestReceipt ( "twitch-msg-123" ) ;
150151 vi . mocked ( sendMessageTwitchInternal ) . mockResolvedValue ( {
151- ok : true ,
152152 messageId : "twitch-msg-123" ,
153153 receipt,
154154 } ) ;
@@ -184,14 +184,14 @@ describe("outbound", () => {
184184 timestamp : expect . any ( Number ) ,
185185 } ) ;
186186 expect ( result ?. receipt . parts . map ( ( part ) => part . kind ) ) . toEqual ( [ "text" ] ) ;
187- expect ( sendMessageTwitchInternal ) . toHaveBeenLastCalledWith (
188- "testchannel" ,
189- "image https://example.com/image.png" ,
190- mockConfig ,
191- "default" ,
192- true ,
193- console ,
194- ) ;
187+ expect ( sendMessageTwitchInternal ) . toHaveBeenLastCalledWith ( {
188+ channel : "testchannel" ,
189+ text : "image https://example.com/image.png" ,
190+ cfg : mockConfig ,
191+ account : mockAccount ,
192+ accountId : "default" ,
193+ clientManager : undefined ,
194+ } ) ;
195195 } ,
196196 messageSendingHooks : ( ) => {
197197 expect ( twitchMessageAdapter . durableFinal ?. capabilities ?. messageSendingHooks ) . toBe ( true ) ;
@@ -343,7 +343,6 @@ describe("outbound", () => {
343343 const { sendMessageTwitchInternal } = await import ( "./send.js" ) ;
344344 setupAccountContext ( ) ;
345345 vi . mocked ( sendMessageTwitchInternal ) . mockResolvedValue ( {
346- ok : true ,
347346 outcome : "not_sent" ,
348347 messageId : "" ,
349348 receipt : createMessageReceiptFromOutboundResults ( { results : [ ] } ) ,
@@ -368,7 +367,6 @@ describe("outbound", () => {
368367
369368 setupAccountContext ( ) ;
370369 vi . mocked ( sendMessageTwitchInternal ) . mockResolvedValue ( {
371- ok : true ,
372370 messageId : "twitch-msg-123" ,
373371 receipt : twitchTestReceipt ( "twitch-msg-123" ) ,
374372 } ) ;
@@ -383,14 +381,14 @@ describe("outbound", () => {
383381 expect ( result . channel ) . toBe ( "twitch" ) ;
384382 expect ( result . messageId ) . toBe ( "twitch-msg-123" ) ;
385383 expect ( result . receipt ?. platformMessageIds ) . toEqual ( [ "twitch-msg-123" ] ) ;
386- expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith (
387- "testchannel" ,
388- "Hello Twitch!" ,
389- mockConfig ,
390- "default" ,
391- true ,
392- console ,
393- ) ;
384+ expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith ( {
385+ channel : "testchannel" ,
386+ text : "Hello Twitch!" ,
387+ cfg : mockConfig ,
388+ account : mockAccount ,
389+ accountId : "default" ,
390+ clientManager : undefined ,
391+ } ) ;
394392 expect ( result . timestamp ) . toBeGreaterThan ( 0 ) ;
395393 } ) ;
396394
@@ -421,12 +419,28 @@ describe("outbound", () => {
421419 ) . rejects . toThrow ( "No channel specified" ) ;
422420 } ) ;
423421
422+ it ( "rejects an unconfigured account before attempting delivery" , async ( ) => {
423+ const { sendMessageTwitchInternal } = await import ( "./send.js" ) ;
424+ setupAccountContext ( { configured : false } ) ;
425+
426+ await expect (
427+ twitchOutbound . sendText ! ( {
428+ cfg : mockConfig ,
429+ to : "#testchannel" ,
430+ text : "Hello!" ,
431+ accountId : "default" ,
432+ } ) ,
433+ ) . rejects . toThrow (
434+ "Account default is not properly configured. Required: username, clientId, and token (config or env for default account)." ,
435+ ) ;
436+ expect ( sendMessageTwitchInternal ) . not . toHaveBeenCalled ( ) ;
437+ } ) ;
438+
424439 it ( "should use account channel when target not provided" , async ( ) => {
425440 const { sendMessageTwitchInternal } = await import ( "./send.js" ) ;
426441
427442 setupAccountContext ( ) ;
428443 vi . mocked ( sendMessageTwitchInternal ) . mockResolvedValue ( {
429- ok : true ,
430444 messageId : "msg-456" ,
431445 receipt : twitchTestReceipt ( "msg-456" ) ,
432446 } ) ;
@@ -438,14 +452,14 @@ describe("outbound", () => {
438452 accountId : "default" ,
439453 } ) ;
440454
441- expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith (
442- "testchannel" ,
443- "Hello!" ,
444- mockConfig ,
445- "default" ,
446- true ,
447- console ,
448- ) ;
455+ expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith ( {
456+ channel : "testchannel" ,
457+ text : "Hello!" ,
458+ cfg : mockConfig ,
459+ account : mockAccount ,
460+ accountId : "default" ,
461+ clientManager : undefined ,
462+ } ) ;
449463 } ) ;
450464
451465 it ( "uses configured defaultAccount when accountId is omitted" , async ( ) => {
@@ -473,7 +487,6 @@ describe("outbound", () => {
473487 availableAccountIds : [ "default" , "secondary" ] ,
474488 } ) ) ;
475489 vi . mocked ( sendMessageTwitchInternal ) . mockResolvedValue ( {
476- ok : true ,
477490 messageId : "msg-secondary" ,
478491 receipt : twitchTestReceipt ( "msg-secondary" ) ,
479492 } ) ;
@@ -492,26 +505,21 @@ describe("outbound", () => {
492505 text : "Hello!" ,
493506 } ) ;
494507
495- expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith (
496- "secondary-channel" ,
497- "Hello!" ,
498- defaultAccountConfig ,
499- "secondary" ,
500- true ,
501- console ,
502- ) ;
508+ expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith ( {
509+ channel : "secondary-channel" ,
510+ text : "Hello!" ,
511+ cfg : defaultAccountConfig ,
512+ account : { ... mockAccount , channel : "secondary-channel" } ,
513+ accountId : "secondary" ,
514+ clientManager : undefined ,
515+ } ) ;
503516 } ) ;
504517
505518 it ( "should throw on send failure" , async ( ) => {
506519 const { sendMessageTwitchInternal } = await import ( "./send.js" ) ;
507520
508521 setupAccountContext ( ) ;
509- vi . mocked ( sendMessageTwitchInternal ) . mockResolvedValue ( {
510- ok : false ,
511- messageId : "failed-msg" ,
512- receipt : createMessageReceiptFromOutboundResults ( { results : [ ] } ) ,
513- error : "Connection lost" ,
514- } ) ;
522+ vi . mocked ( sendMessageTwitchInternal ) . mockRejectedValue ( new Error ( "Connection lost" ) ) ;
515523
516524 await expect (
517525 twitchOutbound . sendText ! ( {
@@ -530,7 +538,6 @@ describe("outbound", () => {
530538
531539 setupAccountContext ( ) ;
532540 vi . mocked ( sendMessageTwitchInternal ) . mockResolvedValue ( {
533- ok : true ,
534541 messageId : "media-msg-123" ,
535542 receipt : twitchTestReceipt ( "media-msg-123" ) ,
536543 } ) ;
@@ -546,22 +553,21 @@ describe("outbound", () => {
546553 expect ( result . channel ) . toBe ( "twitch" ) ;
547554 expect ( result . messageId ) . toBe ( "media-msg-123" ) ;
548555 expect ( result . receipt ?. platformMessageIds ) . toEqual ( [ "media-msg-123" ] ) ;
549- expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith (
550- "testchannel" ,
551- "Check this: https://example.com/image.png" ,
552- mockConfig ,
553- "default" ,
554- true ,
555- console ,
556- ) ;
556+ expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith ( {
557+ channel : "testchannel" ,
558+ text : "Check this: https://example.com/image.png" ,
559+ cfg : mockConfig ,
560+ account : mockAccount ,
561+ accountId : "default" ,
562+ clientManager : undefined ,
563+ } ) ;
557564 } ) ;
558565
559566 it ( "should send media URL only when no text" , async ( ) => {
560567 const { sendMessageTwitchInternal } = await import ( "./send.js" ) ;
561568
562569 setupAccountContext ( ) ;
563570 vi . mocked ( sendMessageTwitchInternal ) . mockResolvedValue ( {
564- ok : true ,
565571 messageId : "media-only-msg" ,
566572 receipt : twitchTestReceipt ( "media-only-msg" ) ,
567573 } ) ;
@@ -574,14 +580,14 @@ describe("outbound", () => {
574580 accountId : "default" ,
575581 } ) ;
576582
577- expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith (
578- "testchannel" ,
579- "https://example.com/image.png" ,
580- mockConfig ,
581- "default" ,
582- true ,
583- console ,
584- ) ;
583+ expect ( sendMessageTwitchInternal ) . toHaveBeenCalledWith ( {
584+ channel : "testchannel" ,
585+ text : "https://example.com/image.png" ,
586+ cfg : mockConfig ,
587+ account : mockAccount ,
588+ accountId : "default" ,
589+ clientManager : undefined ,
590+ } ) ;
585591 } ) ;
586592 } ) ;
587593} ) ;
0 commit comments