Skip to content

Commit 4a029a6

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(quickbooks): validate bill allocations before account lookup
1 parent c1b08f1 commit 4a029a6

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

apps/sim/tools/quickbooks/create_bill_payment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export const quickbooksCreateBillPaymentTool: ToolConfig<
158158
maxResponseBytes: QUICKBOOKS_MAX_RESPONSE_BYTES,
159159
},
160160
directExecution: async (params, signal) => {
161+
const body = buildQuickBooksCreateBillPaymentBody(params)
161162
const paymentAccountId = params.paymentAccountId.trim()
162163
if (!paymentAccountId) throw new Error('paymentAccountId is required')
163164

@@ -188,7 +189,7 @@ export const quickbooksCreateBillPaymentTool: ToolConfig<
188189
{
189190
method: 'POST',
190191
headers: getQuickBooksToolHeaders(params.accessToken, 'application/json'),
191-
body: JSON.stringify(buildQuickBooksCreateBillPaymentBody(params)),
192+
body: JSON.stringify(body),
192193
signal,
193194
}
194195
)

apps/sim/tools/quickbooks/purchasing.test.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,41 @@ describe('QuickBooks BillPayment account compatibility', () => {
500500
const mutationUrl = new URL(fetchMock.mock.calls[1][0] as URL)
501501
expect(mutationUrl.pathname).toBe('/v3/company/123456789/billpayment')
502502
expect(mutationUrl.searchParams.get('requestid')).toBe('sanitized-request-id')
503-
expect(JSON.parse(fetchMock.mock.calls[1][1].body as string)).toMatchObject({
504-
PayType: payType,
505-
})
503+
expect(JSON.parse(fetchMock.mock.calls[1][1].body as string)).toEqual(
504+
buildQuickBooksCreateBillPaymentBody({ ...params, paymentType })
505+
)
506506
}
507507
)
508508

509+
it.each([
510+
['allocation-total mismatch', [{ billId: '12', amount: 24 }]],
511+
['empty allocations', []],
512+
['malformed allocation', [null]],
513+
[
514+
'duplicate Bill IDs',
515+
[
516+
{ billId: '12', amount: 12.5 },
517+
{ billId: '12', amount: 12.5 },
518+
],
519+
],
520+
['non-finite allocation', [{ billId: '12', amount: Number.POSITIVE_INFINITY }]],
521+
[
522+
'more than 100 allocations',
523+
Array.from({ length: 101 }, (_, index) => ({ billId: String(index), amount: 1 })),
524+
],
525+
])('rejects %s before fetching the payment account', async (_name, billAllocations) => {
526+
const fetchMock = vi.fn()
527+
vi.stubGlobal('fetch', fetchMock)
528+
529+
await expect(
530+
quickbooksCreateBillPaymentTool.directExecution!({
531+
...params,
532+
billAllocations: billAllocations as QuickBooksCreateBillPaymentParams['billAllocations'],
533+
})
534+
).rejects.toThrow()
535+
expect(fetchMock).not.toHaveBeenCalled()
536+
})
537+
509538
it.each([
510539
['check', 'Credit Card', 'Bank'],
511540
['credit_card', 'Bank', 'Credit Card'],

0 commit comments

Comments
 (0)