@@ -63,10 +63,48 @@ describe('parseOracleFusionCollection', () => {
6363 { items : [ ] , count : 0 , hasMore : false , limit : 25 , offset : 5 , totalResults : 6 } ,
6464 { items : [ { } ] , count : 1 , hasMore : false , limit : 25 , offset : 5 , totalResults : 7 } ,
6565 { items : [ { } ] , count : 1 , hasMore : true , limit : 25 , offset : 5 , totalResults : 6 } ,
66- ] ) ( 'rejects pagination metadata that contradicts total results %#' , ( value ) => {
67- expect ( ( ) => parseOracleFusionCollection ( value , ( item ) => item ) ) . toThrow (
68- 'hasMore contradicts totalResults'
69- )
66+ { items : [ { } ] , count : 1 , hasMore : false , limit : 25 , offset : 4 , totalResults : 4 } ,
67+ { items : [ { } ] , count : 1 , hasMore : true , limit : 25 , offset : 5 , totalResults : 4 } ,
68+ { items : [ { } ] , count : 1 , hasMore : false , limit : 25 , offset : 5 , totalResults : 0 } ,
69+ { items : [ { } ] , count : 1 , hasMore : true , limit : 25 , offset : 5 , totalResults : 0 } ,
70+ ] ) ( 'preserves estimated totals independently of pagination metadata %#' , ( value ) => {
71+ expect ( parseOracleFusionCollection ( value , ( item ) => item ) ) . toEqual ( {
72+ ...value ,
73+ nextOffset : value . offset + value . count ,
74+ } )
75+ } )
76+
77+ it . each (
78+ [
79+ - 1 ,
80+ 0.5 ,
81+ '1' ,
82+ null ,
83+ true ,
84+ { } ,
85+ [ ] ,
86+ Number . NaN ,
87+ Number . POSITIVE_INFINITY ,
88+ Number . NEGATIVE_INFINITY ,
89+ Number . MAX_SAFE_INTEGER + 1 ,
90+ ] . map ( ( totalResults ) => ( { totalResults } ) )
91+ ) ( 'rejects malformed estimated total $totalResults' , ( { totalResults } ) => {
92+ const parseItem = vi . fn ( ( item ) => item )
93+ expect ( ( ) =>
94+ parseOracleFusionCollection (
95+ { items : [ { } ] , count : 1 , hasMore : false , limit : 25 , offset : 0 , totalResults } ,
96+ parseItem
97+ )
98+ ) . toThrow ( 'Oracle collection totalResults must be a non-negative safe integer' )
99+ expect ( parseItem ) . not . toHaveBeenCalled ( )
100+ } )
101+
102+ it ( 'does not synthesize an omitted total for a nonempty page' , ( ) => {
103+ const page = { items : [ { } ] , count : 1 , hasMore : true , limit : 25 , offset : 5 }
104+ const result = parseOracleFusionCollection ( page , ( item ) => item )
105+
106+ expect ( result ) . toEqual ( { ...page , nextOffset : 6 } )
107+ expect ( result ) . not . toHaveProperty ( 'totalResults' )
70108 } )
71109
72110 it ( 'accepts omitted items only for an unambiguous empty terminal page' , ( ) => {
@@ -118,7 +156,6 @@ describe('parseOracleFusionCollection', () => {
118156 [ { items : [ { } ] , count : 0 , hasMore : false , limit : 25 , offset : 0 } , 'match' ] ,
119157 [ { items : [ ] , count : 0 , hasMore : true , limit : 25 , offset : 0 } , 'empty page' ] ,
120158 [ { items : [ ] , count : 0 , hasMore : false , limit : 0 , offset : 0 } , 'positive' ] ,
121- [ { items : [ { } ] , count : 1 , hasMore : false , limit : 25 , offset : 4 , totalResults : 4 } , 'smaller' ] ,
122159 [
123160 { items : [ { } ] , count : 1 , hasMore : true , limit : 25 , offset : Number . MAX_SAFE_INTEGER } ,
124161 'safe integer range' ,
0 commit comments