11import * as sinon from 'sinon' ;
22import { expect } from 'chai' ;
3- import { CancellationTokenSource , extensions } from 'vscode' ;
3+ import { CancellationTokenSource , commands , extensions } from 'vscode' ;
44import { CodeQLExtensionInterface } from '../../../extension' ;
55import { logger } from '../../../logging' ;
66import * as config from '../../../config' ;
@@ -115,7 +115,7 @@ describe('Variant Analysis Monitor', async function() {
115115
116116 describe ( 'when there are successfully scanned repos' , async ( ) => {
117117 beforeEach ( async function ( ) {
118- scannedRepos = createMockScannedRepos ( [ 'pending' , 'in_progress' , 'succeeded' ] ) ;
118+ scannedRepos = createMockScannedRepos ( [ 'pending' , 'pending' , ' in_progress' , 'in_progress' , 'succeeded' , 'succeeded ', 'succeeded' ] ) ;
119119 mockApiResponse = createMockApiResponse ( 'completed' , scannedRepos ) ;
120120 mockGetVariantAnalysis = sandbox . stub ( ghApiClient , 'getVariantAnalysis' ) . resolves ( mockApiResponse ) ;
121121 } ) ;
@@ -127,6 +127,21 @@ describe('Variant Analysis Monitor', async function() {
127127 expect ( result . status ) . to . equal ( 'CompletedSuccessfully' ) ;
128128 expect ( result . scannedReposDownloaded ) . to . eql ( scannedRepoIds ) ;
129129 } ) ;
130+
131+ it ( 'should trigger a download extension command for each repo' , async ( ) => {
132+ const succeededRepos = scannedRepos . filter ( r => r . analysis_status === 'succeeded' ) ;
133+ const commandSpy = sandbox . spy ( commands , 'executeCommand' ) ;
134+
135+ await variantAnalysisMonitor . monitorVariantAnalysis ( variantAnalysis , cancellationTokenSource . token ) ;
136+
137+ expect ( commandSpy ) . to . have . callCount ( succeededRepos . length ) ;
138+
139+ succeededRepos . forEach ( ( succeededRepo , index ) => {
140+ expect ( commandSpy . getCall ( index ) . args [ 0 ] ) . to . eq ( 'codeQL.autoDownloadVariantAnalysisResult' ) ;
141+ expect ( commandSpy . getCall ( index ) . args [ 1 ] ) . to . eq ( succeededRepo ) ;
142+ expect ( commandSpy . getCall ( index ) . args [ 2 ] ) . to . eq ( mockApiResponse ) ;
143+ } ) ;
144+ } ) ;
130145 } ) ;
131146
132147 describe ( 'when there are only in progress repos' , async ( ) => {
0 commit comments