@@ -254,10 +254,11 @@ describe("fetchValidActionIds", () => {
254254 ] ) ;
255255 assert . strictEqual ( sourceDB . _calls . select . length , 1 ) ;
256256 assert . deepStrictEqual ( sourceDB . _calls . select [ 0 ] , [
257+ "idlink_va" ,
257258 "idaction_name" ,
258259 "idaction_url" ,
259260 ] ) ;
260- assert . deepStrictEqual ( sourceDB . _calls . distinct , [ true ] ) ;
261+ assert . deepStrictEqual ( sourceDB . _calls . distinct , [ ] ) ; // no distinct
261262 } ) ;
262263
263264 it ( "should apply idsite and date filters" , async ( ) => {
@@ -271,21 +272,48 @@ describe("fetchValidActionIds", () => {
271272 assert . strictEqual ( sourceDB . _calls . where [ 1 ] [ 1 ] , ">=" ) ;
272273 } ) ;
273274
274- it ( "should use pagination with limit and offset " , async ( ) => {
275+ it ( "should use cursor-based pagination on idlink_va " , async ( ) => {
275276 const sourceDB = createMockDB ( { selectResults : [ [ ] ] } ) ;
276277 await fetchValidActionIds ( sourceDB , 1 , 0 , ( ) => { } ) ;
277278
278279 assert . deepStrictEqual ( sourceDB . _calls . limit , [ 1000 ] ) ;
279- assert . deepStrictEqual ( sourceDB . _calls . offset , [ 0 ] ) ;
280+ assert . deepStrictEqual ( sourceDB . _calls . offset , [ ] ) ; // no offset
281+ assert . deepStrictEqual ( sourceDB . _calls . orderBy , [ "idlink_va" ] ) ;
282+ // cursor where: idlink_va > 0
283+ const cursorWhere = sourceDB . _calls . where . find (
284+ ( w ) => Array . isArray ( w ) && w [ 0 ] === "idlink_va" ,
285+ ) ;
286+ assert . deepStrictEqual ( cursorWhere , [ "idlink_va" , ">" , 0 ] ) ;
287+ } ) ;
288+
289+ it ( "should advance cursor using last idlink_va of each batch" , async ( ) => {
290+ const sourceDB = createMockDB ( {
291+ selectResults : [
292+ [
293+ { idlink_va : 10 , idaction_name : 1 , idaction_url : 2 } ,
294+ { idlink_va : 20 , idaction_name : 3 , idaction_url : 4 } ,
295+ ] ,
296+ [ ] , // End pagination
297+ ] ,
298+ } ) ;
299+
300+ await fetchValidActionIds ( sourceDB , 1 , 0 , ( ) => { } ) ;
301+
302+ // Second call should use cursor idlink_va > 20
303+ const cursorWheres = sourceDB . _calls . where . filter (
304+ ( w ) => Array . isArray ( w ) && w [ 0 ] === "idlink_va" ,
305+ ) ;
306+ assert . deepStrictEqual ( cursorWheres [ 0 ] , [ "idlink_va" , ">" , 0 ] ) ;
307+ assert . deepStrictEqual ( cursorWheres [ 1 ] , [ "idlink_va" , ">" , 20 ] ) ;
280308 } ) ;
281309
282310 it ( "should collect unique action IDs from multiple batches" , async ( ) => {
283311 const sourceDB = createMockDB ( {
284312 selectResults : [
285313 [
286- { idaction_name : 1 , idaction_url : 2 } ,
287- { idaction_name : 1 , idaction_url : 3 } ,
288- { idaction_name : null , idaction_url : 4 } ,
314+ { idlink_va : 1 , idaction_name : 1 , idaction_url : 2 } ,
315+ { idlink_va : 2 , idaction_name : 1 , idaction_url : 3 } ,
316+ { idlink_va : 3 , idaction_name : null , idaction_url : 4 } ,
289317 ] ,
290318 [ ] , // End pagination
291319 ] ,
@@ -304,8 +332,8 @@ describe("fetchValidActionIds", () => {
304332 const sourceDB = createMockDB ( {
305333 selectResults : [
306334 [
307- { idaction_name : 5 , idaction_url : 10 } ,
308- { idaction_name : 3 , idaction_url : 15 } ,
335+ { idlink_va : 1 , idaction_name : 5 , idaction_url : 10 } ,
336+ { idlink_va : 2 , idaction_name : 3 , idaction_url : 15 } ,
309337 ] ,
310338 [ ] ,
311339 ] ,
0 commit comments