Skip to content

Commit 772ea72

Browse files
authored
test(amazonq): add unit tests for authUtil (#7263)
## Problem There are no unit tests for the new AuthUtil on Flare LSP ## Solution * Add unit test for core AuthUtil functionality * Create a test util for all tests where AuthUtil is needed * Ensure all tests that interact with the AuthUtil consume the new test util * Add destroy method to the AuthUtil class to simplify cleanup for unit tests --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent ae7c222 commit 772ea72

File tree

12 files changed

+231
-451
lines changed

12 files changed

+231
-451
lines changed

packages/amazonq/test/unit/amazonq/backend_amazonq.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ describe('Amazon Q Login', async function () {
1616
let sandbox: sinon.SinonSandbox
1717
let backend: backendAmazonQ.AmazonQLoginWebview
1818

19-
await createTestAuthUtil()
20-
21-
beforeEach(function () {
19+
beforeEach(async function () {
20+
await createTestAuthUtil()
2221
sandbox = sinon.createSandbox()
2322
backend = new backendAmazonQ.AmazonQLoginWebview()
2423
})
@@ -101,6 +100,8 @@ describe('Amazon Q Login', async function () {
101100
})
102101

103102
it('signs out of reauth and emits telemetry', async function () {
103+
await getStartUrl.connectToEnterpriseSso(startUrl, region)
104+
104105
await backend.signout()
105106

106107
assert.ok(!AuthUtil.instance.isConnected())

packages/amazonq/test/unit/codewhisperer/commands/invokeRecommendation.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import assert from 'assert'
77
import * as sinon from 'sinon'
8-
import { resetCodeWhispererGlobalVariables, createMockTextEditor } from 'aws-core-vscode/test'
8+
import { resetCodeWhispererGlobalVariables, createMockTextEditor, createTestAuthUtil } from 'aws-core-vscode/test'
99
import {
1010
ConfigurationEntry,
1111
invokeRecommendation,
@@ -20,6 +20,7 @@ describe('invokeRecommendation', function () {
2020
let mockClient: DefaultCodeWhispererClient
2121

2222
beforeEach(async function () {
23+
await createTestAuthUtil()
2324
await resetCodeWhispererGlobalVariables()
2425
getRecommendationStub = sinon.stub(InlineCompletionService.instance, 'getPaginatedRecommendation')
2526
})

packages/amazonq/test/unit/codewhisperer/region/regionProfileManager.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ describe('RegionProfileManager', async function () {
2323
description: 'foo description',
2424
}
2525

26-
await createTestAuthUtil()
27-
2826
async function setupConnection(type: 'builderId' | 'idc') {
2927
if (type === 'builderId') {
3028
await AuthUtil.instance.login(constants.builderIdStartUrl, region)
@@ -37,7 +35,8 @@ describe('RegionProfileManager', async function () {
3735
}
3836
}
3937

40-
beforeEach(function () {
38+
beforeEach(async function () {
39+
await createTestAuthUtil()
4140
regionProfileManager = new RegionProfileManager(AuthUtil.instance)
4241
})
4342

packages/amazonq/test/unit/codewhisperer/service/inlineCompletionService.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import {
1919
listCodeWhispererCommandsId,
2020
DefaultCodeWhispererClient,
2121
} from 'aws-core-vscode/codewhisperer'
22-
import { createMockTextEditor, resetCodeWhispererGlobalVariables, createMockDocument } from 'aws-core-vscode/test'
22+
import {
23+
createMockTextEditor,
24+
resetCodeWhispererGlobalVariables,
25+
createMockDocument,
26+
createTestAuthUtil,
27+
} from 'aws-core-vscode/test'
2328

2429
describe('inlineCompletionService', function () {
2530
beforeEach(async function () {
@@ -192,6 +197,7 @@ describe('codewhisperer status bar', function () {
192197
}
193198

194199
beforeEach(async function () {
200+
await createTestAuthUtil()
195201
await resetCodeWhispererGlobalVariables()
196202
sandbox = sinon.createSandbox()
197203
statusBar = new TestStatusBar()

packages/amazonq/test/unit/codewhisperer/service/keyStrokeHandler.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as sinon from 'sinon'
99
import * as codewhispererSdkClient from 'aws-core-vscode/codewhisperer'
1010
import {
1111
createMockTextEditor,
12+
createTestAuthUtil,
1213
createTextDocumentChangeEvent,
1314
resetCodeWhispererGlobalVariables,
1415
} from 'aws-core-vscode/test'
@@ -160,13 +161,16 @@ describe('keyStrokeHandler', function () {
160161

161162
describe('invokeAutomatedTrigger', function () {
162163
let mockClient: codewhispererSdkClient.DefaultCodeWhispererClient
164+
163165
beforeEach(async function () {
166+
await createTestAuthUtil()
164167
sinon.restore()
165168
mockClient = new codewhispererSdkClient.DefaultCodeWhispererClient()
166169
await resetCodeWhispererGlobalVariables()
167170
sinon.stub(mockClient, 'listRecommendations')
168171
sinon.stub(mockClient, 'generateRecommendations')
169172
})
173+
170174
afterEach(function () {
171175
sinon.restore()
172176
})

0 commit comments

Comments
 (0)