Skip to content

Commit 1f5006d

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
test(quickbooks): cover missing PDF content type
1 parent 0421404 commit 1f5006d

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

apps/sim/app/api/tools/quickbooks/documents.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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: {

apps/sim/app/api/tools/quickbooks/download-transaction-pdf/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)