@@ -470,9 +470,9 @@ describe("issues command", () => {
470470 "test-repo" ,
471471 ] ) ;
472472
473- expect ( console . log ) . toHaveBeenCalledWith (
474- expect . stringContaining ( '"Potential SQL injection vulnerability"' ) ,
475- ) ;
473+ const jsonOutput = ( console . log as ReturnType < typeof vi . fn > ) . mock . calls [ 0 ] [ 0 ] ;
474+ expect ( jsonOutput ) . toContain ( '"Potential SQL injection vulnerability"' ) ;
475+ expect ( jsonOutput ) . toContain ( '"sql-injection"' ) ;
476476 } ) ;
477477
478478 it ( "should output JSON for overview when --overview --output json is specified" , async ( ) => {
@@ -498,6 +498,120 @@ describe("issues command", () => {
498498 ) ;
499499 } ) ;
500500
501+ it ( "should pass a custom limit <= 100 directly to the API" , async ( ) => {
502+ vi . mocked ( AnalysisService . searchRepositoryIssues ) . mockResolvedValue ( {
503+ data : [ ] ,
504+ } as any ) ;
505+
506+ const program = createProgram ( ) ;
507+ await program . parseAsync ( [
508+ "node" ,
509+ "test" ,
510+ "issues" ,
511+ "gh" ,
512+ "test-org" ,
513+ "test-repo" ,
514+ "--limit" ,
515+ "50" ,
516+ ] ) ;
517+
518+ expect ( AnalysisService . searchRepositoryIssues ) . toHaveBeenCalledWith (
519+ "gh" ,
520+ "test-org" ,
521+ "test-repo" ,
522+ undefined ,
523+ 50 ,
524+ { } ,
525+ ) ;
526+ } ) ;
527+
528+ it ( "should paginate when limit > 100" , async ( ) => {
529+ const page1Issues = Array . from ( { length : 100 } , ( _ , i ) => ( {
530+ issueId : `issue-${ i } ` ,
531+ resultDataId : i ,
532+ filePath : `file-${ i } .ts` ,
533+ fileId : i ,
534+ patternInfo : { id : "p1" , category : "Style" , severityLevel : "Warning" , level : "Warning" } ,
535+ toolInfo : { uuid : "t1" , name : "Tool" } ,
536+ lineNumber : 1 ,
537+ message : `Issue ${ i } ` ,
538+ language : "TypeScript" ,
539+ lineText : "x" ,
540+ falsePositiveThreshold : 0.5 ,
541+ } ) ) ;
542+ const page2Issues = Array . from ( { length : 50 } , ( _ , i ) => ( {
543+ issueId : `issue-${ 100 + i } ` ,
544+ resultDataId : 100 + i ,
545+ filePath : `file-${ 100 + i } .ts` ,
546+ fileId : 100 + i ,
547+ patternInfo : { id : "p1" , category : "Style" , severityLevel : "Warning" , level : "Warning" } ,
548+ toolInfo : { uuid : "t1" , name : "Tool" } ,
549+ lineNumber : 1 ,
550+ message : `Issue ${ 100 + i } ` ,
551+ language : "TypeScript" ,
552+ lineText : "x" ,
553+ falsePositiveThreshold : 0.5 ,
554+ } ) ) ;
555+
556+ vi . mocked ( AnalysisService . searchRepositoryIssues )
557+ . mockResolvedValueOnce ( {
558+ data : page1Issues ,
559+ pagination : { cursor : "cursor-2" , limit : 100 , total : 250 } ,
560+ } as any )
561+ . mockResolvedValueOnce ( {
562+ data : page2Issues ,
563+ pagination : { cursor : undefined , limit : 100 , total : 250 } ,
564+ } as any ) ;
565+
566+ const program = createProgram ( ) ;
567+ await program . parseAsync ( [
568+ "node" ,
569+ "test" ,
570+ "issues" ,
571+ "gh" ,
572+ "test-org" ,
573+ "test-repo" ,
574+ "--limit" ,
575+ "150" ,
576+ ] ) ;
577+
578+ expect ( AnalysisService . searchRepositoryIssues ) . toHaveBeenCalledTimes ( 2 ) ;
579+ // First call: no cursor
580+ expect ( AnalysisService . searchRepositoryIssues ) . toHaveBeenNthCalledWith (
581+ 1 , "gh" , "test-org" , "test-repo" , undefined , 100 , { } ,
582+ ) ;
583+ // Second call: with cursor from first response
584+ expect ( AnalysisService . searchRepositoryIssues ) . toHaveBeenNthCalledWith (
585+ 2 , "gh" , "test-org" , "test-repo" , "cursor-2" , 100 , { } ,
586+ ) ;
587+
588+ const output = getAllOutput ( ) ;
589+ expect ( output ) . toContain ( "Issues — Found 250 issues" ) ;
590+ } ) ;
591+
592+ it ( "should cap limit at 1000" , async ( ) => {
593+ vi . mocked ( AnalysisService . searchRepositoryIssues ) . mockResolvedValue ( {
594+ data : [ ] ,
595+ } as any ) ;
596+
597+ const program = createProgram ( ) ;
598+ await program . parseAsync ( [
599+ "node" ,
600+ "test" ,
601+ "issues" ,
602+ "gh" ,
603+ "test-org" ,
604+ "test-repo" ,
605+ "--limit" ,
606+ "5000" ,
607+ ] ) ;
608+
609+ // Should use pageSize 100 (min of 1000, 100)
610+ expect ( AnalysisService . searchRepositoryIssues ) . toHaveBeenCalledWith (
611+ "gh" , "test-org" , "test-repo" , undefined , 100 , { } ,
612+ ) ;
613+ } ) ;
614+
501615 it ( "should fail when CODACY_API_TOKEN is not set" , async ( ) => {
502616 delete process . env . CODACY_API_TOKEN ;
503617
0 commit comments