@@ -534,39 +534,40 @@ describe("downloadMSTeamsBotFrameworkAttachment", () => {
534534 const jsonSpy = vi . spyOn ( Response . prototype , "json" ) . mockImplementation ( async ( ) => {
535535 throw new Error ( "raw response.json() should not be used" ) ;
536536 } ) ;
537- const fetchFn = createMockFetch ( [
538- {
539- match : / \/ v 3 \/ a t t a c h m e n t s \/ a t t - 1 $ / ,
540- response : new Response ( stream , {
541- status : 200 ,
542- headers : { "content-type" : "application/json" } ,
543- } ) ,
544- } ,
545- ] ) ;
546-
547- const warn = vi . fn ( ) ;
548- const media = await downloadMSTeamsBotFrameworkAttachment ( {
549- serviceUrl : "https://smba.trafficmanager.net/amer" ,
550- attachmentId : "att-1" ,
551- tokenProvider : buildTokenProvider ( ) ,
552- maxBytes : 10_000_000 ,
553- fetchFn,
554- fetchFnSupportsDispatcher : true ,
555- resolveFn : resolvePublicHost ,
556- logger : { warn } ,
537+ const fetchFn : typeof fetch = vi . fn ( async ( ) => {
538+ return new Response ( stream , {
539+ status : 200 ,
540+ headers : { "content-type" : "application/json" } ,
541+ } ) ;
557542 } ) ;
558543
559- expect ( media ) . toBeUndefined ( ) ;
560- expect ( jsonSpy ) . not . toHaveBeenCalled ( ) ;
561- // Enforced well before the 64 MiB test ceiling; an unbounded reader would keep pulling.
562- expect ( state . enqueued ) . toBeLessThan ( 32 ) ;
563- expect ( warn ) . toHaveBeenCalledWith (
564- "msteams botFramework attachmentInfo parse failed" ,
565- expect . objectContaining ( {
566- error : expect . stringMatching ( / J S O N r e s p o n s e e x c e e d s 1 6 7 7 7 2 1 6 b y t e s / ) ,
567- } ) ,
568- ) ;
569- jsonSpy . mockRestore ( ) ;
544+ try {
545+ const warn = vi . fn ( ) ;
546+ const media = await downloadMSTeamsBotFrameworkAttachment ( {
547+ serviceUrl : "https://smba.trafficmanager.net/amer" ,
548+ attachmentId : "att-1" ,
549+ tokenProvider : buildTokenProvider ( ) ,
550+ maxBytes : 10_000_000 ,
551+ fetchFn,
552+ fetchFnSupportsDispatcher : true ,
553+ resolveFn : resolvePublicHost ,
554+ logger : { warn } ,
555+ } ) ;
556+
557+ expect ( media ) . toBeUndefined ( ) ;
558+ expect ( jsonSpy ) . not . toHaveBeenCalled ( ) ;
559+ // Enforced well before the 64 MiB test ceiling; an unbounded reader would keep pulling.
560+ expect ( state . enqueued ) . toBeLessThan ( 32 ) ;
561+ expect ( state . canceled ) . toBe ( true ) ;
562+ expect ( warn ) . toHaveBeenCalledWith (
563+ "msteams botFramework attachmentInfo parse failed" ,
564+ expect . objectContaining ( {
565+ error : expect . stringMatching ( / J S O N r e s p o n s e e x c e e d s 1 6 7 7 7 2 1 6 b y t e s / ) ,
566+ } ) ,
567+ ) ;
568+ } finally {
569+ jsonSpy . mockRestore ( ) ;
570+ }
570571 } ) ;
571572 } ) ;
572573} ) ;
0 commit comments