@@ -852,7 +852,12 @@ describe('QuickBooks generic operations', () => {
852852 const result = await quickBooksBatchTool . transformResponse ?.( response , {
853853 accessToken : 'token' ,
854854 realmId : '123145' ,
855- batch : { BatchItemRequest : [ ] } ,
855+ batch : {
856+ BatchItemRequest : [
857+ { bId : 'vendor-query' , Query : 'SELECT * FROM Vendor' } ,
858+ { bId : 'bad-update' , Vendor : { Id : '1' , SyncToken : '0' } , operation : 'update' } ,
859+ ] ,
860+ } ,
856861 } )
857862
858863 expect ( result ?. output ) . toEqual ( {
@@ -863,4 +868,43 @@ describe('QuickBooks generic operations', () => {
863868 time : '2026-01-20T10:00:00-08:00' ,
864869 } )
865870 } )
871+
872+ it ( 'rejects successful QuickBooks batch responses with missing or incomplete items' , async ( ) => {
873+ const params = {
874+ accessToken : 'token' ,
875+ realmId : '123145' ,
876+ batch : {
877+ BatchItemRequest : [
878+ { bId : 'vendor-query' , Query : 'SELECT * FROM Vendor' } ,
879+ { bId : 'bill-query' , Query : 'SELECT * FROM Bill' } ,
880+ ] ,
881+ } ,
882+ }
883+
884+ await expect (
885+ quickBooksBatchTool . transformResponse ?.(
886+ new Response ( JSON . stringify ( { time : '2026-01-20T10:00:00-08:00' } ) , { status : 200 } ) ,
887+ params
888+ )
889+ ) . rejects . toThrow ( 'QuickBooks batch response did not include any item responses' )
890+
891+ await expect (
892+ quickBooksBatchTool . transformResponse ?.(
893+ new Response ( JSON . stringify ( { BatchItemResponse : [ ] } ) , { status : 200 } ) ,
894+ params
895+ )
896+ ) . rejects . toThrow ( 'QuickBooks batch response did not include any item responses' )
897+
898+ await expect (
899+ quickBooksBatchTool . transformResponse ?.(
900+ new Response (
901+ JSON . stringify ( {
902+ BatchItemResponse : [ { bId : 'vendor-query' , QueryResponse : { Vendor : [ { Id : '1' } ] } } ] ,
903+ } ) ,
904+ { status : 200 }
905+ ) ,
906+ params
907+ )
908+ ) . rejects . toThrow ( 'QuickBooks batch response returned 1 of 2 item responses' )
909+ } )
866910} )
0 commit comments