33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import { PromiseResult } from 'aws-sdk/lib/request'
7- import { Stub , stub } from 'aws-core-vscode/test'
6+ import { PromiseResult , Request } from 'aws-sdk/lib/request'
7+ import { createMockDocument } from './testUtil'
8+ import { Stub , stub } from '../utilities/stubber'
89import { AWSError , HttpResponse } from 'aws-sdk'
910import {
1011 CodeAnalysisScope ,
@@ -15,12 +16,13 @@ import {
1516 ListCodeScanFindingsResponse ,
1617 pollScanJobStatus ,
1718 SecurityScanTimedOutError ,
18- } from 'aws-core-vscode /codewhisperer'
19- import { timeoutUtils } from 'aws-core-vscode /shared'
19+ } from '../.. /codewhisperer'
20+ import { timeoutUtils } from '../.. /shared'
2021import assert from 'assert'
21- import sinon from 'sinon'
22+ import * as sinon from 'sinon'
2223import * as vscode from 'vscode'
2324import fs from 'fs' // eslint-disable-line no-restricted-imports
25+ import { GetCodeScanResponse } from '../../codewhisperer/client/codewhispererclient'
2426
2527const buildRawCodeScanIssue = ( params ?: Partial < RawCodeScanIssue > ) : RawCodeScanIssue => ( {
2628 filePath : 'workspaceFolder/python3.7-plain-sam-app/hello_world/app.py' ,
@@ -72,6 +74,8 @@ describe('securityScanHandler', function () {
7274 mockClient = stub ( DefaultCodeWhispererClient )
7375 sinon . stub ( fs , 'existsSync' ) . returns ( true )
7476 sinon . stub ( fs , 'statSync' ) . returns ( { isFile : ( ) => true } as fs . Stats )
77+ const textDocumentMock = createMockDocument ( 'first line\n second line\n fourth line' )
78+ sinon . stub ( vscode . workspace , 'openTextDocument' ) . resolves ( textDocumentMock )
7579 } )
7680
7781 afterEach ( function ( ) {
@@ -290,16 +294,64 @@ describe('securityScanHandler', function () {
290294 it ( 'should return status when scan completes successfully' , async function ( ) {
291295 mockClient . getCodeScan
292296 . onFirstCall ( )
293- . resolves ( { status : 'Pending' , $response : { requestId : 'req1' } } )
297+ . resolves ( {
298+ status : 'Pending' ,
299+ $response : {
300+ requestId : 'req1' ,
301+ hasNextPage : function ( ) : boolean {
302+ throw new Error ( 'Function not implemented.' )
303+ } ,
304+ nextPage : function ( ) : Request < GetCodeScanResponse , AWSError > | null {
305+ throw new Error ( 'Function not implemented.' )
306+ } ,
307+ data : undefined ,
308+ error : undefined ,
309+ redirectCount : 0 ,
310+ retryCount : 0 ,
311+ httpResponse : new HttpResponse ( ) ,
312+ } ,
313+ } )
294314 . onSecondCall ( )
295- . resolves ( { status : 'Completed' , $response : { requestId : 'req2' } } )
315+ . resolves ( {
316+ status : 'Completed' ,
317+ $response : {
318+ requestId : 'req2' ,
319+ hasNextPage : function ( ) : boolean {
320+ throw new Error ( 'Function not implemented.' )
321+ } ,
322+ nextPage : function ( ) : Request < GetCodeScanResponse , AWSError > | null {
323+ throw new Error ( 'Function not implemented.' )
324+ } ,
325+ data : undefined ,
326+ error : undefined ,
327+ redirectCount : 0 ,
328+ retryCount : 0 ,
329+ httpResponse : new HttpResponse ( ) ,
330+ } ,
331+ } )
296332
297333 const result = await pollScanJobStatus ( mockClient , mockJobId , CodeAnalysisScope . FILE_AUTO , mockStartTime )
298334 assert . strictEqual ( result , 'Completed' )
299335 } )
300336
301337 it ( 'should throw SecurityScanTimedOutError when polling exceeds timeout for express scans' , async function ( ) {
302- mockClient . getCodeScan . resolves ( { status : 'Pending' , $response : { requestId : 'req1' } } )
338+ mockClient . getCodeScan . resolves ( {
339+ status : 'Pending' ,
340+ $response : {
341+ requestId : 'req1' ,
342+ hasNextPage : function ( ) : boolean {
343+ throw new Error ( 'Function not implemented.' )
344+ } ,
345+ nextPage : function ( ) : Request < GetCodeScanResponse , AWSError > | null {
346+ throw new Error ( 'Function not implemented.' )
347+ } ,
348+ data : undefined ,
349+ error : undefined ,
350+ redirectCount : 0 ,
351+ retryCount : 0 ,
352+ httpResponse : new HttpResponse ( ) ,
353+ } ,
354+ } )
303355
304356 const pollPromise = pollScanJobStatus ( mockClient , mockJobId , CodeAnalysisScope . FILE_AUTO , mockStartTime )
305357
@@ -310,7 +362,23 @@ describe('securityScanHandler', function () {
310362 } )
311363
312364 it ( 'should throw SecurityScanTimedOutError when polling exceeds timeout for standard scans' , async function ( ) {
313- mockClient . getCodeScan . resolves ( { status : 'Pending' , $response : { requestId : 'req1' } } )
365+ mockClient . getCodeScan . resolves ( {
366+ status : 'Pending' ,
367+ $response : {
368+ requestId : 'req1' ,
369+ hasNextPage : function ( ) : boolean {
370+ throw new Error ( 'Function not implemented.' )
371+ } ,
372+ nextPage : function ( ) : Request < GetCodeScanResponse , AWSError > | null {
373+ throw new Error ( 'Function not implemented.' )
374+ } ,
375+ data : undefined ,
376+ error : undefined ,
377+ redirectCount : 0 ,
378+ retryCount : 0 ,
379+ httpResponse : new HttpResponse ( ) ,
380+ } ,
381+ } )
314382
315383 const pollPromise = pollScanJobStatus ( mockClient , mockJobId , CodeAnalysisScope . PROJECT , mockStartTime )
316384
0 commit comments