6
6
import assert from 'assert'
7
7
import * as vscode from 'vscode'
8
8
import * as sinon from 'sinon'
9
- import * as got from 'got'
10
9
import * as semver from 'semver'
11
10
import { DefaultCodeWhispererClient } from '../../../codewhisperer/client/codewhisperer'
12
11
import * as startSecurityScan from '../../../codewhisperer/commands/startSecurityScan'
@@ -21,14 +20,14 @@ import { HttpResponse } from 'aws-sdk'
21
20
import { getTestWindow } from '../../shared/vscode/window'
22
21
import { SeverityLevel } from '../../shared/vscode/message'
23
22
import { cancel } from '../../../shared/localizedText'
24
- import { sleep } from '../../../shared/utilities/timeoutUtils'
25
23
import {
26
24
codeScanLogsOutputChannelId ,
27
25
showScannedFilesMessage ,
28
26
stopScanMessage ,
29
27
} from '../../../codewhisperer/models/constants'
30
28
import * as model from '../../../codewhisperer/models/model'
31
29
import { CodewhispererSecurityScan } from '../../../shared/telemetry/telemetry.gen'
30
+ import { getFetchStubWithResponse } from '../../common/request.test'
32
31
33
32
const mockCreateCodeScanResponse = {
34
33
$response : {
@@ -177,7 +176,7 @@ describe('startSecurityScan', function () {
177
176
} )
178
177
179
178
it ( 'Should render security scan result' , async function ( ) {
180
- sinon . stub ( got , 'default' ) . resolves ( { statusCode : 200 } )
179
+ getFetchStubWithResponse ( { status : 200 , statusText : 'testing stub' } )
181
180
const commandSpy = sinon . spy ( vscode . commands , 'executeCommand' )
182
181
const securityScanRenderSpy = sinon . spy ( diagnosticsProvider , 'initSecurityScanRender' )
183
182
@@ -194,11 +193,7 @@ describe('startSecurityScan', function () {
194
193
} )
195
194
196
195
it ( 'Should stop security scan' , async function ( ) {
197
- sinon . stub ( got , 'default' ) . callsFake ( ( ) => {
198
- return sleep ( 1000 ) . then ( ( ) => {
199
- return { statusCode : 200 }
200
- } ) as any
201
- } )
196
+ getFetchStubWithResponse ( { status : 200 , statusText : 'testing stub' } )
202
197
const securityScanRenderSpy = sinon . spy ( diagnosticsProvider , 'initSecurityScanRender' )
203
198
const securityScanStoppedErrorSpy = sinon . spy ( model , 'CodeScanStoppedError' )
204
199
const testWindow = getTestWindow ( )
@@ -223,11 +218,7 @@ describe('startSecurityScan', function () {
223
218
} )
224
219
225
220
it ( 'Should not stop security scan when not confirmed' , async function ( ) {
226
- sinon . stub ( got , 'default' ) . callsFake ( ( ) => {
227
- return sleep ( 1000 ) . then ( ( ) => {
228
- return { statusCode : 200 }
229
- } ) as any
230
- } )
221
+ getFetchStubWithResponse ( { status : 200 , statusText : 'testing stub' } )
231
222
const securityScanRenderSpy = sinon . spy ( diagnosticsProvider , 'initSecurityScanRender' )
232
223
const securityScanStoppedErrorSpy = sinon . spy ( model , 'CodeScanStoppedError' )
233
224
const testWindow = getTestWindow ( )
@@ -256,7 +247,7 @@ describe('startSecurityScan', function () {
256
247
this . skip ( )
257
248
}
258
249
const commandSpy = sinon . spy ( vscode . commands , 'executeCommand' )
259
- sinon . stub ( got , 'default' ) . resolves ( { statusCode : 200 } )
250
+ getFetchStubWithResponse ( { status : 200 , statusText : 'testing stub' } )
260
251
const testWindow = getTestWindow ( )
261
252
testWindow . onDidShowMessage ( message => {
262
253
if ( message . message . includes ( 'Security scan completed' ) ) {
0 commit comments