@@ -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