@@ -108,6 +108,39 @@ describe("GET /api/modules", () => {
108108 expect ( mockRange ) . toHaveBeenCalledWith ( 10 , 19 ) ;
109109 } ) ;
110110
111+ it ( "falls back to defaults for invalid pagination values" , async ( ) => {
112+ const req = makeRequest ( "http://localhost/api/modules?page=nope&limit=Infinity" ) ;
113+ const res = await GET ( req ) ;
114+ const body = await res . json ( ) ;
115+
116+ expect ( res . status ) . toBe ( 200 ) ;
117+ expect ( body . page ) . toBe ( 1 ) ;
118+ expect ( body . limit ) . toBe ( 20 ) ;
119+ expect ( mockRange ) . toHaveBeenCalledWith ( 0 , 19 ) ;
120+ } ) ;
121+
122+ it ( "does not truncate fractional pagination values" , async ( ) => {
123+ const req = makeRequest ( "http://localhost/api/modules?page=2.5&limit=10.9" ) ;
124+ const res = await GET ( req ) ;
125+ const body = await res . json ( ) ;
126+
127+ expect ( res . status ) . toBe ( 200 ) ;
128+ expect ( body . page ) . toBe ( 1 ) ;
129+ expect ( body . limit ) . toBe ( 20 ) ;
130+ expect ( mockRange ) . toHaveBeenCalledWith ( 0 , 19 ) ;
131+ } ) ;
132+
133+ it ( "caps valid limit values at 50" , async ( ) => {
134+ const req = makeRequest ( "http://localhost/api/modules?page=2&limit=99" ) ;
135+ const res = await GET ( req ) ;
136+ const body = await res . json ( ) ;
137+
138+ expect ( res . status ) . toBe ( 200 ) ;
139+ expect ( body . page ) . toBe ( 2 ) ;
140+ expect ( body . limit ) . toBe ( 50 ) ;
141+ expect ( mockRange ) . toHaveBeenCalledWith ( 50 , 99 ) ;
142+ } ) ;
143+
111144 it ( "handles database errors" , async ( ) => {
112145 resetChain ( {
113146 rangeResult : { data : null , error : { message : "DB error" } , count : null } ,
0 commit comments