Skip to content

Commit e78f232

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
test(quickbooks): cover attachment MIME fallback
1 parent 1f5006d commit e78f232

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,28 @@ describe('QuickBooks document API routes', () => {
346346
)
347347
})
348348

349+
it('uses the binary fallback MIME type when an attachment response omits Content-Type', async () => {
350+
mockFetch.mockResolvedValueOnce(
351+
new Response('https://intuit-download.example/attachment.bin', {
352+
headers: { 'content-type': 'text/plain' },
353+
})
354+
)
355+
mockSecureFetchWithPinnedIP.mockResolvedValueOnce(new Response(new Uint8Array([1, 2, 3])))
356+
357+
const response = await downloadAttachment(
358+
createMockRequest('POST', { ...auth, attachmentId: '16' })
359+
)
360+
const body = await response.json()
361+
362+
expect(response.status).toBe(200)
363+
expect(body.output).toMatchObject({
364+
attachmentId: '16',
365+
fileName: 'attachment.bin',
366+
mimeType: 'application/octet-stream',
367+
size: 3,
368+
})
369+
})
370+
349371
it('rejects note-only and oversized attachment downloads', async () => {
350372
mockFetch.mockResolvedValueOnce(new Response(''))
351373
const note = await downloadAttachment(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
104104
})
105105
if (buffer.length === 0) throw new Error('QuickBooks attachment file is empty')
106106
const mimeType =
107-
downloadResponse.headers.get('content-type')?.split(';', 1)[0].trim().toLowerCase() ||
107+
downloadResponse.headers.get('content-type')?.split(';', 1)[0]?.trim().toLowerCase() ||
108108
'application/octet-stream'
109109
let fallbackName = `quickbooks-attachment-${attachmentId}`
110110
try {

0 commit comments

Comments
 (0)