Skip to content

Commit fea44c8

Browse files
committed
fix(amazonq): Fix showSsoPrompt unit tests
1 parent 8787af3 commit fea44c8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ 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
16+
let useDeviceFlowStub: sinon.SinonStub
1517

1618
beforeEach(async function () {
1719
await resetCodeWhispererGlobalVariables()
1820
isBuilderIdConnection = sinon.stub(AuthUtil.instance, 'isBuilderIdConnection')
1921
isBuilderIdConnection.resolves()
22+
23+
// Stub useDeviceFlow so we always use DeviceFlow for auth
24+
useDeviceFlowStub = sinon.stub(SsoAccessTokenProvider, 'useDeviceFlow').returns(true)
2025
})
2126

2227
afterEach(function () {
@@ -36,12 +41,13 @@ describe('showConnectionPrompt', function () {
3641
assert.ok(isBuilderIdConnection)
3742
})
3843

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

4248
await awsIdSignIn()
4349

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

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)