@@ -11,105 +11,136 @@ import { TestFeatures } from '@aws/language-server-runtimes/testing'
11
11
import { CodeWhispererServiceToken } from '../codeWhispererService'
12
12
import { Server } from '@aws/language-server-runtimes/server-interface'
13
13
14
- describe ( 'QConfigurationServer' , ( ) => {
15
- describe ( 'OnGetConfigurationFromServer' , ( ) => {
16
- let testFeatures : TestFeatures
17
- let disposeServer : ( ) => void
18
- let listAvailableProfilesStub : sinon . SinonStub
19
- let listAvailableCustomizationsStub : sinon . SinonStub
20
-
21
- beforeEach ( ( ) => {
22
- testFeatures = new TestFeatures ( )
23
-
24
- const codeWhispererService = stubInterface < CodeWhispererServiceToken > ( )
25
- const configurationServerFactory : Server = QConfigurationServerToken ( ( ) => codeWhispererService )
26
-
27
- listAvailableCustomizationsStub = sinon . stub (
28
- ServerConfigurationProvider . prototype ,
29
- 'listAvailableCustomizations'
30
- )
31
- listAvailableProfilesStub = sinon . stub ( ServerConfigurationProvider . prototype , 'listAvailableProfiles' )
32
-
33
- disposeServer = configurationServerFactory ( testFeatures )
34
- } )
14
+ describe ( 'QConfigurationServerToken' , ( ) => {
15
+ let testFeatures : TestFeatures
16
+ let disposeServer : ( ) => void
17
+ let listAvailableProfilesStub : sinon . SinonStub
18
+ let listAvailableCustomizationsStub : sinon . SinonStub
19
+ let qDeveloperProfilesEnabledPropertyStub : sinon . SinonStub
20
+ let qDeveloperProfilesEnabledSetterSpy : sinon . SinonSpy
21
+
22
+ beforeEach ( ( ) => {
23
+ testFeatures = new TestFeatures ( )
24
+
25
+ const codeWhispererService = stubInterface < CodeWhispererServiceToken > ( )
26
+ const configurationServerFactory : Server = QConfigurationServerToken ( ( ) => codeWhispererService )
27
+
28
+ listAvailableCustomizationsStub = sinon . stub (
29
+ ServerConfigurationProvider . prototype ,
30
+ 'listAvailableCustomizations'
31
+ )
32
+ listAvailableProfilesStub = sinon . stub ( ServerConfigurationProvider . prototype , 'listAvailableProfiles' )
33
+ qDeveloperProfilesEnabledSetterSpy = sinon . spy ( )
34
+ qDeveloperProfilesEnabledPropertyStub = sinon
35
+ . stub ( ServerConfigurationProvider . prototype , 'qDeveloperProfilesEnabled' )
36
+ . set ( qDeveloperProfilesEnabledSetterSpy )
37
+
38
+ disposeServer = configurationServerFactory ( testFeatures )
39
+ } )
35
40
36
- afterEach ( ( ) => {
37
- sinon . restore ( )
38
- } )
41
+ afterEach ( ( ) => {
42
+ sinon . restore ( )
43
+ } )
39
44
40
- // WIP: temporary test case until client can signal they support developer profiles
41
- it ( `calls all list methods when ${ Q_CONFIGURATION_SECTION } is requested` , ( ) => {
42
- testFeatures . lsp . extensions . onGetConfigurationFromServer . firstCall . firstArg ( {
43
- section : Q_CONFIGURATION_SECTION ,
45
+ it ( `enables Q developer profiles when signalled by client` , ( ) => {
46
+ const initialize = ( developerProfiles : boolean ) => {
47
+ testFeatures . lsp . addInitializer . firstCall . firstArg ( {
48
+ initializationOptions : {
49
+ aws : {
50
+ awsClientCapabilities : {
51
+ q : {
52
+ developerProfiles,
53
+ } ,
54
+ } ,
55
+ } ,
56
+ } ,
44
57
} )
58
+ }
59
+
60
+ initialize ( false )
61
+ sinon . assert . calledWith ( qDeveloperProfilesEnabledSetterSpy . firstCall , false )
62
+
63
+ initialize ( true )
64
+ sinon . assert . calledWith ( qDeveloperProfilesEnabledSetterSpy . secondCall , true )
65
+ } )
45
66
46
- sinon . assert . calledOnce ( listAvailableCustomizationsStub )
47
- sinon . assert . calledOnce ( listAvailableProfilesStub )
67
+ it ( `calls all list methods when ${ Q_CONFIGURATION_SECTION } is requested` , ( ) => {
68
+ testFeatures . lsp . extensions . onGetConfigurationFromServer . firstCall . firstArg ( {
69
+ section : Q_CONFIGURATION_SECTION ,
48
70
} )
49
71
50
- it ( `only calls listAvailableCustomizations when ${ Q_CUSTOMIZATIONS_CONFIGURATION_SECTION } is requested` , ( ) => {
51
- testFeatures . lsp . extensions . onGetConfigurationFromServer . firstCall . firstArg ( {
52
- section : Q_CUSTOMIZATIONS_CONFIGURATION_SECTION ,
53
- } )
72
+ sinon . assert . calledOnce ( listAvailableCustomizationsStub )
73
+ sinon . assert . calledOnce ( listAvailableProfilesStub )
74
+ } )
54
75
55
- sinon . assert . calledOnce ( listAvailableCustomizationsStub )
56
- sinon . assert . notCalled ( listAvailableProfilesStub )
76
+ it ( `only calls listAvailableCustomizations when ${ Q_CUSTOMIZATIONS_CONFIGURATION_SECTION } is requested` , ( ) => {
77
+ testFeatures . lsp . extensions . onGetConfigurationFromServer . firstCall . firstArg ( {
78
+ section : Q_CUSTOMIZATIONS_CONFIGURATION_SECTION ,
57
79
} )
58
80
59
- it ( `only calls listAvailableProfiles when ${ Q_DEVELOPER_PROFILES_CONFIGURATION_SECTION } is requested` , ( ) => {
60
- testFeatures . lsp . extensions . onGetConfigurationFromServer . firstCall . firstArg ( {
61
- section : Q_DEVELOPER_PROFILES_CONFIGURATION_SECTION ,
62
- } )
81
+ sinon . assert . calledOnce ( listAvailableCustomizationsStub )
82
+ sinon . assert . notCalled ( listAvailableProfilesStub )
83
+ } )
63
84
64
- sinon . assert . notCalled ( listAvailableCustomizationsStub )
65
- sinon . assert . calledOnce ( listAvailableProfilesStub )
85
+ it ( `only calls listAvailableProfiles when ${ Q_DEVELOPER_PROFILES_CONFIGURATION_SECTION } is requested` , ( ) => {
86
+ testFeatures . lsp . extensions . onGetConfigurationFromServer . firstCall . firstArg ( {
87
+ section : Q_DEVELOPER_PROFILES_CONFIGURATION_SECTION ,
66
88
} )
89
+
90
+ sinon . assert . notCalled ( listAvailableCustomizationsStub )
91
+ sinon . assert . calledOnce ( listAvailableProfilesStub )
67
92
} )
93
+ } )
68
94
69
- describe ( 'ServerConfigurationProvider' , ( ) => {
70
- let serverConfigurationProvider : ServerConfigurationProvider
71
- let codeWhispererService : StubbedInstance < CodeWhispererServiceToken >
72
- let testFeatures : TestFeatures
73
- let listAvailableProfilesHandlerSpy : sinon . SinonSpy
74
-
75
- beforeEach ( ( ) => {
76
- codeWhispererService = stubInterface < CodeWhispererServiceToken > ( )
77
- codeWhispererService . listAvailableCustomizations . resolves ( {
78
- customizations : [ ] ,
79
- $response : { } as any ,
80
- } )
95
+ describe ( 'ServerConfigurationProvider' , ( ) => {
96
+ let serverConfigurationProvider : ServerConfigurationProvider
97
+ let codeWhispererService : StubbedInstance < CodeWhispererServiceToken >
98
+ let testFeatures : TestFeatures
99
+ let listAvailableProfilesHandlerSpy : sinon . SinonSpy
100
+
101
+ beforeEach ( ( ) => {
102
+ codeWhispererService = stubInterface < CodeWhispererServiceToken > ( )
103
+ codeWhispererService . listAvailableCustomizations . resolves ( {
104
+ customizations : [ ] ,
105
+ $response : { } as any ,
106
+ } )
81
107
82
- testFeatures = new TestFeatures ( )
108
+ testFeatures = new TestFeatures ( )
83
109
84
- serverConfigurationProvider = new ServerConfigurationProvider (
85
- codeWhispererService ,
86
- testFeatures . credentialsProvider ,
87
- testFeatures . logging ,
88
- ( ) => codeWhispererService
89
- )
110
+ serverConfigurationProvider = new ServerConfigurationProvider (
111
+ codeWhispererService ,
112
+ testFeatures . credentialsProvider ,
113
+ testFeatures . logging ,
114
+ ( ) => codeWhispererService
115
+ )
90
116
91
- listAvailableProfilesHandlerSpy = sinon . spy (
92
- serverConfigurationProvider ,
93
- 'listAllAvailableProfilesHandler' as keyof ServerConfigurationProvider
94
- )
95
- } )
117
+ listAvailableProfilesHandlerSpy = sinon . spy (
118
+ serverConfigurationProvider ,
119
+ 'listAllAvailableProfilesHandler' as keyof ServerConfigurationProvider
120
+ )
121
+ } )
96
122
97
- afterEach ( ( ) => {
98
- sinon . restore ( )
99
- } )
123
+ afterEach ( ( ) => {
124
+ sinon . restore ( )
125
+ } )
100
126
101
- it ( `calls corresponding API when listAvailableCustomizations is invoked` , async ( ) => {
102
- await serverConfigurationProvider . listAvailableCustomizations ( )
127
+ it ( `calls corresponding API when listAvailableCustomizations is invoked` , async ( ) => {
128
+ await serverConfigurationProvider . listAvailableCustomizations ( )
103
129
104
- sinon . assert . calledOnce ( codeWhispererService . listAvailableCustomizations )
105
- } )
130
+ sinon . assert . calledOnce ( codeWhispererService . listAvailableCustomizations )
131
+ } )
106
132
107
- // WIP: alter test case when client can signal they support developer profiles
108
- it ( `does not use corresponding handler when listAvailableProfiles is invoked` , async ( ) => {
109
- const result = await serverConfigurationProvider . listAvailableProfiles ( )
133
+ it ( `does not use listAvailableProfiles handler when developer profiles is disabled` , async ( ) => {
134
+ const result = await serverConfigurationProvider . listAvailableProfiles ( )
110
135
111
- sinon . assert . notCalled ( listAvailableProfilesHandlerSpy )
112
- assert . deepStrictEqual ( result , [ ] )
113
- } )
136
+ sinon . assert . notCalled ( listAvailableProfilesHandlerSpy )
137
+ assert . deepStrictEqual ( result , [ ] )
138
+ } )
139
+
140
+ it ( `uses listAvailableProfiles handler when developer profiles is enabled` , async ( ) => {
141
+ serverConfigurationProvider . qDeveloperProfilesEnabled = true
142
+ await serverConfigurationProvider . listAvailableProfiles ( )
143
+
144
+ sinon . assert . called ( listAvailableProfilesHandlerSpy )
114
145
} )
115
146
} )
0 commit comments