Skip to content

Commit 4b0ec4d

Browse files
authored
fix(amazonq): Fix showSsoPrompt unit tests (#7236)
## Problem `showConnectionPrompt` unit tests were failing ## Solution * Ensure DeviceFlow is used for auth * Stub login * Assert whether the login was called with builder ID instead of if the log line was emitted --- - 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 8787af3 commit 4b0ec4d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/amazonq/test/unit/codewhisperer/util/showSsoPrompt.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import * as vscode from 'vscode'
77
import assert from 'assert'
88
import * as sinon from 'sinon'
99
import { resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test'
10-
import { assertTelemetryCurried, getTestWindow, getTestLogger } from 'aws-core-vscode/test'
10+
import { assertTelemetryCurried, getTestWindow } from 'aws-core-vscode/test'
1111
import { AuthUtil, awsIdSignIn, showCodeWhispererConnectionPrompt } from 'aws-core-vscode/codewhisperer'
12+
import { SsoAccessTokenProvider, constants } from 'aws-core-vscode/auth'
1213

1314
describe('showConnectionPrompt', function () {
1415
let isBuilderIdConnection: sinon.SinonStub
@@ -17,13 +18,18 @@ describe('showConnectionPrompt', function () {
1718
await resetCodeWhispererGlobalVariables()
1819
isBuilderIdConnection = sinon.stub(AuthUtil.instance, 'isBuilderIdConnection')
1920
isBuilderIdConnection.resolves()
21+
22+
// Stub useDeviceFlow so we always use DeviceFlow for auth
23+
sinon.stub(SsoAccessTokenProvider, 'useDeviceFlow').returns(true)
2024
})
2125

2226
afterEach(function () {
2327
sinon.restore()
2428
})
2529

2630
it('can select connect to AwsBuilderId', async function () {
31+
sinon.stub(AuthUtil.instance, 'login').resolves()
32+
2733
getTestWindow().onDidShowQuickPick(async (picker) => {
2834
await picker.untilReady()
2935
picker.acceptItem(picker.items[0])
@@ -36,12 +42,13 @@ describe('showConnectionPrompt', function () {
3642
assert.ok(isBuilderIdConnection)
3743
})
3844

39-
it('connectToAwsBuilderId logs that AWS ID sign in was selected', async function () {
45+
it('connectToAwsBuilderId calls AuthUtil login with builderIdStartUrl', async function () {
4046
sinon.stub(vscode.commands, 'executeCommand')
47+
const loginStub = sinon.stub(AuthUtil.instance, 'login').resolves()
4148

4249
await awsIdSignIn()
4350

44-
const loggedEntries = getTestLogger().getLoggedEntries()
45-
assert.ok(loggedEntries.find((entry) => entry === 'selected AWS ID sign in'))
51+
assert.strictEqual(loginStub.called, true)
52+
assert.strictEqual(loginStub.firstCall.args[0], constants.builderIdStartUrl)
4653
})
4754
})

packages/core/src/auth/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export { LoginManager } from './deprecated/loginManager'
2525
export * as constants from './sso/constants'
2626
export * as authUtils from './utils'
2727
export * as auth2 from './auth2'
28+
export * as SsoAccessTokenProvider from './sso/ssoAccessTokenProvider'

0 commit comments

Comments
 (0)