@@ -9,6 +9,7 @@ import * as vscode from 'vscode'
99import { Auth } from '../../auth/auth'
1010import { ToolkitError } from '../../shared/errors'
1111import * as authUtils from '../../auth/utils'
12+ import { getTestWindow } from '../shared/vscode/window'
1213
1314describe ( 'getConnectionIdFromProfile' , function ( ) {
1415 it ( 'constructs connection ID from profile name' , function ( ) {
@@ -35,16 +36,39 @@ describe('setupConsoleConnection', function () {
3536
3637 it ( 'creates connection after successful console login' , async function ( ) {
3738 const executeCommandStub = sandbox . stub ( vscode . commands , 'executeCommand' ) . resolves ( )
39+ const getConnectionStub = sandbox
40+ . stub ( Auth . instance , 'getConnection' )
41+ . resolves ( { id : 'profile:test-profile' } as any )
3842 const useConnectionStub = sandbox . stub ( Auth . instance , 'useConnection' ) . resolves ( )
3943
4044 await authUtils . setupConsoleConnection ( 'test-profile' , 'us-east-1' )
4145
4246 assert . ok ( executeCommandStub . calledOnceWith ( 'aws.toolkit.auth.consoleLogin' , 'test-profile' , 'us-east-1' ) )
47+ assert . ok ( getConnectionStub . calledOnceWith ( { id : 'profile:test-profile' } ) )
4348 assert . ok ( useConnectionStub . calledOnceWith ( { id : 'profile:test-profile' } ) )
4449 } )
4550
51+ it ( 'throws error when connection was not created' , async function ( ) {
52+ sandbox . stub ( vscode . commands , 'executeCommand' ) . resolves ( )
53+ sandbox . stub ( Auth . instance , 'getConnection' ) . resolves ( undefined )
54+ getTestWindow ( ) . onDidShowMessage ( ( m ) => m . close ( ) )
55+
56+ await assert . rejects (
57+ ( ) => authUtils . setupConsoleConnection ( 'test-profile' , 'us-east-1' ) ,
58+ ( err : ToolkitError ) => {
59+ assert . strictEqual (
60+ err . message ,
61+ 'Unable to connect to AWS. Console login was cancelled or did not complete successfully.'
62+ )
63+ assert . strictEqual ( err . cancelled , true )
64+ return true
65+ }
66+ )
67+ } )
68+
4669 it ( 'throws error when useConnection fails' , async function ( ) {
4770 sandbox . stub ( vscode . commands , 'executeCommand' ) . resolves ( )
71+ sandbox . stub ( Auth . instance , 'getConnection' ) . resolves ( { id : 'profile:test-profile' } as any )
4872 const error = new Error ( 'useConnection failed' )
4973 sandbox . stub ( Auth . instance , 'useConnection' ) . rejects ( error )
5074
0 commit comments