@@ -580,7 +580,7 @@ describe('QuickBooks generic operations', () => {
580580 } )
581581
582582 const documentResult = await quickBooksDownloadDocumentTool . transformResponse ?.(
583- new Response ( new Uint8Array ( [ 37 , 80 , 68 , 70 ] ) , {
583+ new Response ( new Uint8Array ( [ 37 , 80 , 68 , 70 , 45 ] ) , {
584584 headers : { 'content-type' : 'application/pdf' } ,
585585 status : 200 ,
586586 } ) ,
@@ -595,15 +595,15 @@ describe('QuickBooks generic operations', () => {
595595 file : {
596596 name : 'PurchaseOrder-42.pdf' ,
597597 mimeType : 'application/pdf' ,
598- data : 'JVBERg= =' ,
599- size : 4 ,
598+ data : 'JVBERi0 =' ,
599+ size : 5 ,
600600 } ,
601601 entity : 'PurchaseOrder' ,
602602 recordId : '42' ,
603603 } )
604604
605605 const sentDocumentResult = await quickBooksSendDocumentTool . transformResponse ?.(
606- new Response ( new Uint8Array ( [ 37 , 80 , 68 , 70 ] ) , {
606+ new Response ( new Uint8Array ( [ 37 , 80 , 68 , 70 , 45 ] ) , {
607607 headers : { 'content-type' : 'application/octet-stream' } ,
608608 status : 200 ,
609609 } ) ,
@@ -619,8 +619,8 @@ describe('QuickBooks generic operations', () => {
619619 file : {
620620 name : 'PurchaseOrder-42.pdf' ,
621621 mimeType : 'application/pdf' ,
622- data : 'JVBERg= =' ,
623- size : 4 ,
622+ data : 'JVBERi0 =' ,
623+ size : 5 ,
624624 } ,
625625 entity : 'PurchaseOrder' ,
626626 recordId : '42' ,
@@ -642,6 +642,37 @@ describe('QuickBooks generic operations', () => {
642642 } )
643643 } )
644644
645+ it ( 'rejects successful document responses that are not PDFs' , async ( ) => {
646+ const params = {
647+ accessToken : 'token' ,
648+ realmId : '123145' ,
649+ entity : 'PurchaseOrder' as const ,
650+ recordId : '42' ,
651+ }
652+
653+ await expect (
654+ quickBooksDownloadDocumentTool . transformResponse ?.(
655+ new Response ( JSON . stringify ( { Fault : { Error : [ { Message : 'Unexpected response' } ] } } ) , {
656+ headers : { 'content-type' : 'application/json' } ,
657+ status : 200 ,
658+ } ) ,
659+ params
660+ )
661+ ) . rejects . toThrow ( 'QuickBooks PDF download returned a non-PDF response (application/json)' )
662+
663+ await expect (
664+ quickBooksSendDocumentTool . transformResponse ?.(
665+ new Response ( '' , {
666+ headers : { 'content-type' : 'text/plain' } ,
667+ status : 200 ,
668+ } ) ,
669+ params
670+ )
671+ ) . rejects . toThrow (
672+ 'QuickBooks sent document returned a non-PDF response (text/plain): Empty response'
673+ )
674+ } )
675+
645676 it ( 'transforms QuickBooks batch item responses without hiding item faults' , async ( ) => {
646677 const response = new Response (
647678 JSON . stringify ( {
0 commit comments