Skip to content

Commit c1d1391

Browse files
committed
fix: unit tests
1 parent a09e2a2 commit c1d1391

File tree

3 files changed

+5
-33
lines changed

3 files changed

+5
-33
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,10 @@ describe('AuthUtil', async function () {
435435

436436
assert.ok(mockIamLogin.login.calledOnce)
437437
assert.ok(
438-
mockIamLogin.login.calledWith({
438+
mockIamLogin.login.calledWithMatch({
439439
accessKey: 'accessKey',
440440
secretKey: 'secretKey',
441+
sessionToken: 'sessionToken',
441442
})
442443
)
443444
assert.strictEqual(response, mockResponse)
@@ -523,7 +524,7 @@ describe('AuthUtil', async function () {
523524
await auth.getIamCredential()
524525
assert.fail('Should have thrown an error')
525526
} catch (err) {
526-
assert.strictEqual((err as Error).message, 'Cannot get token with SSO session')
527+
assert.strictEqual((err as Error).message, 'Cannot get credential with SSO session')
527528
}
528529
})
529530

packages/core/src/auth/auth2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ export class IamLogin extends BaseLogin {
645645
}
646646

647647
// Update cached credentials and credential ID
648-
if (response.credential.credentials.accessKeyId && response.credential.credentials.secretAccessKey) {
648+
if (response.credential?.credentials?.accessKeyId && response.credential?.credentials?.secretAccessKey) {
649649
this._data = {
650650
accessKey: response.credential.credentials.accessKeyId,
651651
secretKey: response.credential.credentials.secretAccessKey,

packages/core/src/test/credentials/auth2.test.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ describe('LanguageClientAuth', () => {
230230

231231
sinon.assert.calledOnce(client.sendRequest)
232232
sinon.assert.calledWith(client.sendRequest, invalidateStsCredentialRequestType.method, {
233-
profileName: profileName,
233+
iamCredentialId: profileName,
234234
})
235235
sinon.assert.match(result, { success: true })
236236
})
@@ -631,7 +631,6 @@ describe('IamLogin', () => {
631631
let lspAuth: sinon.SinonStubbedInstance<LanguageClientAuth>
632632
let iamLogin: IamLogin
633633
let eventEmitter: vscode.EventEmitter<any>
634-
let fireEventSpy: sinon.SinonSpy
635634

636635
const loginOpts = {
637636
accessKey: 'test-access-key',
@@ -657,7 +656,6 @@ describe('IamLogin', () => {
657656
beforeEach(() => {
658657
lspAuth = sinon.createStubInstance(LanguageClientAuth)
659658
eventEmitter = new vscode.EventEmitter()
660-
fireEventSpy = sinon.spy(eventEmitter, 'fire')
661659
iamLogin = new IamLogin(profileName, lspAuth as any, eventEmitter)
662660
;(iamLogin as any).eventEmitter = eventEmitter
663661
;(iamLogin as any).connectionState = 'notConnected'
@@ -789,33 +787,6 @@ describe('IamLogin', () => {
789787
})
790788

791789
sinon.assert.match(iamLogin.getConnectionState(), 'expired')
792-
sinon.assert.calledOnce(fireEventSpy)
793-
sinon.assert.calledWith(fireEventSpy, {
794-
id: profileName,
795-
state: 'expired',
796-
})
797-
})
798-
799-
it('emits refresh event when credential is refreshed', () => {
800-
;(iamLogin as any).stsCredentialChangedHandler({
801-
kind: StsCredentialChangedKind.Refreshed,
802-
stsCredentialId: 'test-credential-id',
803-
})
804-
805-
sinon.assert.calledOnce(fireEventSpy)
806-
sinon.assert.calledWith(fireEventSpy, {
807-
id: profileName,
808-
state: 'refreshed',
809-
})
810-
})
811-
812-
it('does not emit event for different credential ID', () => {
813-
;(iamLogin as any).stsCredentialChangedHandler({
814-
kind: StsCredentialChangedKind.Refreshed,
815-
stsCredentialId: 'different-credential-id',
816-
})
817-
818-
sinon.assert.notCalled(fireEventSpy)
819790
})
820791
})
821792
})

0 commit comments

Comments
 (0)