3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
+ import * as vscode from 'vscode'
6
7
import assert from 'assert'
7
- import { RuleEngine } from '../../notifications/rules'
8
+ import { RuleEngine , getRuleContext } from '../../notifications/rules'
8
9
import { DisplayIf , ToolkitNotification , RuleContext } from '../../notifications/types'
9
- import { globals } from '../../shared'
10
+ import globals from '../../shared/extensionGlobals'
11
+ import { Connection , scopesCodeCatalyst } from '../../auth/connection'
12
+ import { getOperatingSystem } from '../../shared/telemetry/util'
13
+ import { getAuthFormIdsFromConnection } from '../../auth/utils'
14
+ import { builderIdStartUrl } from '../../auth/sso/model'
15
+ import { amazonQScopes } from '../../codewhisperer'
10
16
11
17
describe ( 'Notifications Rule Engine' , function ( ) {
12
18
const context : RuleContext = {
@@ -126,6 +132,18 @@ describe('Notifications Rule Engine', function () {
126
132
) ,
127
133
true
128
134
)
135
+ assert . equal (
136
+ ruleEngine . shouldDisplayNotification (
137
+ buildNotification ( {
138
+ extensionVersion : {
139
+ type : 'range' ,
140
+ lowerInclusive : '-inf' ,
141
+ upperExclusive : '1.23.0' ,
142
+ } ,
143
+ } )
144
+ ) ,
145
+ true
146
+ )
129
147
130
148
assert . equal (
131
149
ruleEngine . shouldDisplayNotification (
@@ -138,6 +156,31 @@ describe('Notifications Rule Engine', function () {
138
156
) ,
139
157
true
140
158
)
159
+ assert . equal (
160
+ ruleEngine . shouldDisplayNotification (
161
+ buildNotification ( {
162
+ extensionVersion : {
163
+ type : 'range' ,
164
+ lowerInclusive : '1.0.0' ,
165
+ upperExclusive : '+inf' ,
166
+ } ,
167
+ } )
168
+ ) ,
169
+ true
170
+ )
171
+
172
+ assert . equal (
173
+ ruleEngine . shouldDisplayNotification (
174
+ buildNotification ( {
175
+ extensionVersion : {
176
+ type : 'range' ,
177
+ lowerInclusive : '-inf' ,
178
+ upperExclusive : '+inf' ,
179
+ } ,
180
+ } )
181
+ ) ,
182
+ true
183
+ )
141
184
} )
142
185
143
186
it ( 'should NOT display notification with invalid version range criteria' , function ( ) {
@@ -153,6 +196,18 @@ describe('Notifications Rule Engine', function () {
153
196
) ,
154
197
false
155
198
)
199
+ assert . equal (
200
+ ruleEngine . shouldDisplayNotification (
201
+ buildNotification ( {
202
+ extensionVersion : {
203
+ type : 'range' ,
204
+ lowerInclusive : '-inf' ,
205
+ upperExclusive : '1.20.0' ,
206
+ } ,
207
+ } )
208
+ ) ,
209
+ false
210
+ )
156
211
} )
157
212
158
213
it ( 'should display notification with version OR criteria' , function ( ) {
@@ -365,7 +420,7 @@ describe('Notifications Rule Engine', function () {
365
420
assert . equal (
366
421
ruleEngine . shouldDisplayNotification (
367
422
buildNotification ( {
368
- additionalCriteria : [ { type : 'InstalledExtensions' , values : [ 'ext1' , 'ext2' , 'unkownExtension ' ] } ] ,
423
+ additionalCriteria : [ { type : 'InstalledExtensions' , values : [ 'ext1' , 'ext2' , 'unknownExtension ' ] } ] ,
369
424
} )
370
425
) ,
371
426
false
@@ -473,3 +528,56 @@ describe('Notifications Rule Engine', function () {
473
528
)
474
529
} )
475
530
} )
531
+
532
+ describe ( 'Notifications getRuleContext()' , function ( ) {
533
+ it ( 'should return the correct rule context' , async function ( ) {
534
+ const context = globals . context
535
+ context . extension . packageJSON . version = '0.0.1'
536
+ const authEnabledConnections = (
537
+ [
538
+ {
539
+ type : 'iam' ,
540
+ } ,
541
+ {
542
+ type : 'sso' ,
543
+ scopes : amazonQScopes ,
544
+ startUrl : builderIdStartUrl ,
545
+ } ,
546
+ {
547
+ type : 'sso' ,
548
+ scopes : scopesCodeCatalyst ,
549
+ startUrl : builderIdStartUrl ,
550
+ } ,
551
+ {
552
+ type : 'sso' ,
553
+ scopes : amazonQScopes ,
554
+ startUrl : 'something' ,
555
+ } ,
556
+ {
557
+ type : 'unknown' ,
558
+ } ,
559
+ ] as Connection [ ]
560
+ )
561
+ . map ( ( c ) => getAuthFormIdsFromConnection ( c ) )
562
+ . join ( ',' )
563
+
564
+ const ruleContext = await getRuleContext ( context , {
565
+ authEnabledConnections,
566
+ authScopes : amazonQScopes . join ( ',' ) ,
567
+ authStatus : 'connected' ,
568
+ awsRegion : 'us-east-1' ,
569
+ } )
570
+ assert . deepStrictEqual ( ruleContext , {
571
+ ideVersion : vscode . version ,
572
+ extensionVersion : '0.0.1' ,
573
+ os : getOperatingSystem ( ) ,
574
+ computeEnv : 'test' ,
575
+ authTypes : [ 'credentials' , 'builderId' , 'identityCenter' , 'unknown' ] ,
576
+ authRegions : [ 'us-east-1' ] ,
577
+ authStates : [ 'connected' ] ,
578
+ authScopes : amazonQScopes ,
579
+ installedExtensions : vscode . extensions . all . map ( ( e ) => e . id ) ,
580
+ activeExtensions : vscode . extensions . all . filter ( ( e ) => e . isActive ) . map ( ( e ) => e . id ) ,
581
+ } )
582
+ } )
583
+ } )
0 commit comments