File tree Expand file tree Collapse file tree
apps/sim/app/api/tools/quickbooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -116,6 +116,19 @@ describe('QuickBooks document API routes', () => {
116116 )
117117 expect ( nonPdf . status ) . toBe ( 500 )
118118
119+ mockFetch . mockResolvedValueOnce ( new Response ( new Uint8Array ( Buffer . from ( '%PDF-1.4 fixture' ) ) ) )
120+ const missingContentType = await downloadTransactionPdf (
121+ createMockRequest ( 'POST' , {
122+ ...auth ,
123+ transactionType : 'invoice' ,
124+ transactionId : '1' ,
125+ } )
126+ )
127+ expect ( missingContentType . status ) . toBe ( 500 )
128+ await expect ( missingContentType . json ( ) ) . resolves . toMatchObject ( {
129+ error : 'QuickBooks returned a non-PDF response' ,
130+ } )
131+
119132 mockFetch . mockResolvedValueOnce (
120133 new Response ( '%PDF-' , {
121134 headers : {
Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
5555 } )
5656 if ( ! response . ok ) throw await getQuickBooksDocumentError ( response )
5757
58- const mimeType = response . headers . get ( 'content-type' ) ?. split ( ';' , 1 ) [ 0 ] . trim ( ) . toLowerCase ( )
58+ const mimeType =
59+ response . headers . get ( 'content-type' ) ?. split ( ';' , 1 ) [ 0 ] ?. trim ( ) . toLowerCase ( ) ?? ''
5960 if ( mimeType !== 'application/pdf' ) throw new Error ( 'QuickBooks returned a non-PDF response' )
6061 const buffer = await readResponseToBufferWithLimit ( response , {
6162 maxBytes : MAX_FILE_SIZE ,
You can’t perform that action at this time.
0 commit comments