Skip to content

Commit 787d60e

Browse files
fix(codewhisperer): Fixes some tests that fail when run locally (#3384)
For more info see sim IDE-10578 Signed-off-by: Nikolas Komonen <[email protected]>
1 parent b87fdc2 commit 787d60e

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

src/test/codewhisperer/commands/onAcceptance.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ describe('onAcceptance', function () {
123123
})
124124

125125
it('Should report telemetry that records this user decision event', async function () {
126+
const testStartUrl = 'testStartUrl'
127+
sinon.stub(TelemetryHelper.instance, 'startUrl').value(testStartUrl)
126128
const mockEditor = createMockTextEditor()
127129
RecommendationHandler.instance.requestId = 'test'
128130
RecommendationHandler.instance.sessionId = 'test'
@@ -159,6 +161,7 @@ describe('onAcceptance', function () {
159161
codewhispererSuggestionReferenceCount: 0,
160162
codewhispererCompletionType: 'Line',
161163
codewhispererLanguage: 'python',
164+
credentialStartUrl: testStartUrl,
162165
})
163166
})
164167
})

src/test/codewhisperer/commands/onInlineAcceptance.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ describe('onInlineAcceptance', function () {
4747
})
4848

4949
it('Should report telemetry that records this user decision event', async function () {
50+
const testStartUrl = 'testStartUrl'
51+
sinon.stub(TelemetryHelper.instance, 'startUrl').value(testStartUrl)
5052
const mockEditor = createMockTextEditor()
5153
RecommendationHandler.instance.requestId = 'test'
5254
RecommendationHandler.instance.sessionId = 'test'
@@ -83,6 +85,7 @@ describe('onInlineAcceptance', function () {
8385
codewhispererSuggestionReferenceCount: 0,
8486
codewhispererCompletionType: 'Line',
8587
codewhispererLanguage: 'python',
88+
credentialStartUrl: testStartUrl,
8689
})
8790
})
8891
})

src/test/codewhisperer/explorer/codewhispererNode.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ import { codewhispererNode } from '../../../codewhisperer/explorer/codewhisperer
1010
import { AuthUtil } from '../../../codewhisperer/util/authUtil'
1111

1212
describe('codewhispererNode', function () {
13+
let isConnectionValid: sinon.SinonStub
14+
let isConnected: sinon.SinonStub
15+
16+
beforeEach(function () {
17+
isConnectionValid = sinon.stub(AuthUtil.instance, 'isConnectionValid')
18+
isConnectionValid.returns(false)
19+
20+
isConnected = sinon.stub(AuthUtil.instance, 'isConnected')
21+
isConnected.returns(false)
22+
})
23+
1324
describe('getTreeItem', function () {
1425
afterEach(function () {
1526
sinon.restore()
@@ -26,7 +37,8 @@ describe('codewhispererNode', function () {
2637

2738
it('should create a node showing AWS Builder ID connection', function () {
2839
sinon.stub(AuthUtil.instance, 'isUsingSavedConnection').get(() => true)
29-
sinon.stub(AuthUtil.instance, 'isConnectionValid').resolves(true)
40+
isConnectionValid.returns(true)
41+
3042
const node = codewhispererNode
3143
const treeItem = node.getTreeItem()
3244

@@ -38,8 +50,9 @@ describe('codewhispererNode', function () {
3850

3951
it('should create a node showing enterprise SSO connection', function () {
4052
sinon.stub(AuthUtil.instance, 'isUsingSavedConnection').get(() => true)
41-
sinon.stub(AuthUtil.instance, 'isConnectionValid').resolves(true)
4253
sinon.stub(AuthUtil.instance, 'isEnterpriseSsoInUse').resolves(true)
54+
isConnectionValid.returns(true)
55+
4356
const node = codewhispererNode
4457
const treeItem = node.getTreeItem()
4558

src/test/codewhisperer/service/recommendationHandler.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ describe('recommendationHandler', function () {
3434
const fakeMemeto = new FakeMemento()
3535
const mockClient = stub(DefaultCodeWhispererClient)
3636
const mockEditor = createMockTextEditor()
37+
const testStartUrl = 'testStartUrl'
3738

3839
beforeEach(function () {
3940
sinon.restore()
4041
resetCodeWhispererGlobalVariables()
4142
mockClient.listRecommendations.resolves({})
4243
mockClient.generateRecommendations.resolves({})
44+
sinon.stub(TelemetryHelper.instance, 'startUrl').value(testStartUrl)
4345
})
4446

4547
afterEach(function () {
@@ -130,6 +132,7 @@ describe('recommendationHandler', function () {
130132
codewhispererLineNumber: 1,
131133
codewhispererCursorOffset: 38,
132134
codewhispererLanguage: 'python',
135+
credentialStartUrl: testStartUrl,
133136
})
134137
})
135138

@@ -163,6 +166,7 @@ describe('recommendationHandler', function () {
163166
codewhispererSuggestionReferenceCount: 0,
164167
codewhispererCompletionType: 'Line',
165168
codewhispererLanguage: 'python',
169+
credentialStartUrl: testStartUrl,
166170
})
167171
})
168172
})

src/test/codewhisperer/tracker/codewhispererTracker.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import globals from '../../../shared/extensionGlobals'
99
import { assertTelemetryCurried } from '../../testUtil'
1010
import { CodeWhispererTracker } from '../../../codewhisperer/tracker/codewhispererTracker'
1111
import { resetCodeWhispererGlobalVariables, createAcceptedSuggestionEntry } from '../testUtil'
12+
import { TelemetryHelper } from '../../../codewhisperer/util/telemetryHelper'
1213

1314
describe('codewhispererTracker', function () {
1415
describe('enqueue', function () {
@@ -80,6 +81,8 @@ describe('codewhispererTracker', function () {
8081

8182
describe('emitTelemetryOnSuggestion', function () {
8283
it('Should call recordCodewhispererUserModification with suggestion event', async function () {
84+
const testStartUrl = 'testStartUrl'
85+
sinon.stub(TelemetryHelper.instance, 'startUrl').value(testStartUrl)
8386
const suggestion = createAcceptedSuggestionEntry()
8487
const assertTelemetry = assertTelemetryCurried('codewhisperer_userModification')
8588
await CodeWhispererTracker.getTracker().emitTelemetryOnSuggestion(suggestion)
@@ -91,6 +94,7 @@ describe('codewhispererTracker', function () {
9194
codewhispererModificationPercentage: 1,
9295
codewhispererCompletionType: 'Line',
9396
codewhispererLanguage: 'java',
97+
credentialStartUrl: testStartUrl,
9498
})
9599
})
96100
})

src/test/codewhisperer/util/telemetryHelper.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ describe('telemetryHelper', function () {
7878
codewhispererSuggestionReferenceCount: 0,
7979
codewhispererCompletionType: 'Line',
8080
codewhispererLanguage: 'python',
81-
credentialStartUrl: 'https://view.awsapps.com/start',
8281
})
8382
})
8483
})

0 commit comments

Comments
 (0)