@@ -12,21 +12,17 @@ import { VSCODE_EXTENSION_ID } from '../../shared/extensions'
12
12
import { CodeCatalystClient } from '../../shared/clients/codecatalystClient'
13
13
import { anything , mock , reset , when } from 'ts-mockito'
14
14
import { SeverityLevel } from '../shared/vscode/message'
15
- import { DevEnvironmentId } from '../../codecatalyst/model'
16
15
import { getTestWindow } from '../shared/vscode/window'
16
+ import { builderIdStartUrl } from '../../auth/sso/model'
17
+ import { defaultSsoRegion } from '../../auth/connection'
17
18
18
19
type Stub < T extends ( ...args : any [ ] ) => any > = sinon . SinonStub < Parameters < T > , ReturnType < T > >
19
20
20
21
function createCloneUri ( target : string ) : vscode . Uri {
21
22
return vscode . Uri . parse ( `vscode://${ VSCODE_EXTENSION_ID . awstoolkit } /clone?url=${ encodeURIComponent ( target ) } ` )
22
23
}
23
24
24
- function createConnectUri ( env : DevEnvironmentId ) : vscode . Uri {
25
- const params = {
26
- devEnvironmentId : env . id ,
27
- spaceName : env . org . name ,
28
- projectName : env . project . name ,
29
- }
25
+ function createConnectUri ( params : { [ key : string ] : any } ) : vscode . Uri {
30
26
const encoded = Object . entries ( params )
31
27
. map ( ( [ k , v ] ) => `${ encodeURIComponent ( k ) } =${ encodeURIComponent ( v ) } ` )
32
28
. join ( '&' )
@@ -37,20 +33,10 @@ function createConnectUri(env: DevEnvironmentId): vscode.Uri {
37
33
// The path is apart of our public API! They should not be easy to change.
38
34
39
35
describe ( 'CodeCatalyst handlers' , function ( ) {
40
- let handler : UriHandler
41
36
let commandStub : Stub < typeof vscode . commands . executeCommand >
42
37
const client = mock < CodeCatalystClient > ( )
43
38
44
39
beforeEach ( function ( ) {
45
- handler = new UriHandler ( )
46
- register ( handler , {
47
- openDevEnv : {
48
- execute : async ( ) => undefined ,
49
- } as any ,
50
- cloneRepo : {
51
- execute : async ( ) => undefined ,
52
- } as any ,
53
- } )
54
40
commandStub = sinon . stub ( vscode . commands , 'executeCommand' )
55
41
} )
56
42
@@ -60,6 +46,17 @@ describe('CodeCatalyst handlers', function () {
60
46
} )
61
47
62
48
describe ( 'clone' , function ( ) {
49
+ let handler : UriHandler
50
+
51
+ beforeEach ( function ( ) {
52
+ handler = new UriHandler ( )
53
+ register ( handler , {
54
+ cloneRepo : {
55
+ execute : async ( ) => undefined ,
56
+ } as any ,
57
+ } as any )
58
+ } )
59
+
63
60
it ( 'registers for "/clone"' , function ( ) {
64
61
assert . throws ( ( ) => handler . onPath ( '/clone' , ( ) => { } ) )
65
62
} )
@@ -83,6 +80,42 @@ describe('CodeCatalyst handlers', function () {
83
80
project : { name : 'project' } ,
84
81
}
85
82
83
+ const params = {
84
+ devEnvironmentId : devenvId . id ,
85
+ spaceName : devenvId . org . name ,
86
+ projectName : devenvId . project . name ,
87
+ }
88
+
89
+ let openDevEnvMock : sinon . SinonExpectation
90
+ let handler : UriHandler
91
+
92
+ beforeEach ( function ( ) {
93
+ handler = new UriHandler ( )
94
+ openDevEnvMock = sinon . mock ( )
95
+ register ( handler , {
96
+ openDevEnv : {
97
+ execute : openDevEnvMock ,
98
+ } as any ,
99
+ } as any )
100
+ } )
101
+
102
+ it ( 'returns builder ID SSO if IdC params are not present' , async function ( ) {
103
+ await handler . handleUri ( createConnectUri ( params ) )
104
+ assert . ok (
105
+ openDevEnvMock . calledWith ( devenvId , undefined , {
106
+ startUrl : builderIdStartUrl ,
107
+ region : defaultSsoRegion ,
108
+ } )
109
+ )
110
+ } )
111
+
112
+ it ( 'returns provided IdC params' , async function ( ) {
113
+ const ssoStartUrl = 'https://my-url'
114
+ const ssoRegion = 'us-west-2'
115
+ await handler . handleUri ( createConnectUri ( { ...params , sso_start_url : ssoStartUrl , sso_region : ssoRegion } ) )
116
+ assert . ok ( openDevEnvMock . calledWith ( devenvId , undefined , { startUrl : ssoStartUrl , region : ssoRegion } ) )
117
+ } )
118
+
86
119
it ( 'checks that the environment exists' , async function ( ) {
87
120
// This test is not accurate anymore because dependencies are checked prior to API calls
88
121
// Unit tests are ran without other extensions activated, so this fails on the SSH extension check
0 commit comments