@@ -59,3 +59,45 @@ test('normalizeDapRecords filters out DAP placeholder entries like (other)', ()
5959 assert . equal ( normalized . records [ 0 ] . url , 'https://example.gov' ) ;
6060 assert . equal ( normalized . excluded . filter ( ( e ) => e . reason === 'placeholder_url' ) . length , 2 , 'Should exclude both placeholder entries' ) ;
6161} ) ;
62+
63+ test ( 'getNormalizedTopPages forwards limit as a query param to the API endpoint' , async ( ) => {
64+ let capturedEndpoint ;
65+ const mockFetch = async ( url ) => {
66+ capturedEndpoint = url ;
67+ return {
68+ ok : true ,
69+ json : async ( ) => [ { url : 'https://example.gov' , page_load_count : 1000 } ]
70+ } ;
71+ } ;
72+
73+ await getNormalizedTopPages ( {
74+ endpoint : 'https://api.gsa.gov/analytics/dap/v2.0.0/reports/site/data' ,
75+ limit : 50 ,
76+ sourceDate : '2026-03-01' ,
77+ fetchImpl : mockFetch
78+ } ) ;
79+
80+ const resolved = new URL ( capturedEndpoint ) ;
81+ assert . equal ( resolved . searchParams . get ( 'limit' ) , '50' , 'limit should be forwarded as a query param' ) ;
82+ } ) ;
83+
84+ test ( 'getNormalizedTopPages does not override a limit already present in the endpoint URL' , async ( ) => {
85+ let capturedEndpoint ;
86+ const mockFetch = async ( url ) => {
87+ capturedEndpoint = url ;
88+ return {
89+ ok : true ,
90+ json : async ( ) => [ { url : 'https://example.gov' , page_load_count : 1000 } ]
91+ } ;
92+ } ;
93+
94+ await getNormalizedTopPages ( {
95+ endpoint : 'https://api.gsa.gov/analytics/dap/v2.0.0/reports/site/data?limit=200' ,
96+ limit : 50 ,
97+ sourceDate : '2026-03-01' ,
98+ fetchImpl : mockFetch
99+ } ) ;
100+
101+ const resolved = new URL ( capturedEndpoint ) ;
102+ assert . equal ( resolved . searchParams . get ( 'limit' ) , '200' , 'pre-set limit in endpoint URL should not be overridden' ) ;
103+ } ) ;
0 commit comments