@@ -13,18 +13,26 @@ const STORED_SPLITS: Record<string, ISplit> = {
1313} ;
1414
1515const STORED_SEGMENTS : Record < string , Set < string > > = {
16- 'segment_test ' : new Set ( [ 'emi@split.io' ] ) ,
16+ 'excluded_standard_segment ' : new Set ( [ 'emi@split.io' ] ) ,
1717 'regular_segment' : new Set ( [ 'nadia@split.io' ] )
1818} ;
1919
20+ const STORED_LARGE_SEGMENTS : Record < string , Set < string > > = {
21+ 'excluded_large_segment' : new Set ( [ 'emi-large@split.io' ] )
22+ } ;
23+
2024const STORED_RBSEGMENTS : Record < string , IRBSegment > = {
2125 'mauro_rule_based_segment' : {
2226 changeNumber : 5 ,
2327 name : 'mauro_rule_based_segment' ,
2428 status : 'ACTIVE' ,
2529 excluded : {
2630 keys : [ 'mauro@split.io' , 'gaston@split.io' ] ,
27- segments : [ 'segment_test' ]
31+ segments : [
32+ { type : 'standard' , name : 'excluded_standard_segment' } ,
33+ { type : 'large' , name : 'excluded_large_segment' } ,
34+ { type : 'rule-based' , name : 'excluded_rule_based_segment' }
35+ ]
2836 } ,
2937 conditions : [
3038 {
@@ -87,8 +95,8 @@ const STORED_RBSEGMENTS: Record<string, IRBSegment> = {
8795 changeNumber : 123 ,
8896 status : 'ACTIVE' ,
8997 excluded : {
90- keys : [ ] ,
91- segments : [ ]
98+ keys : null ,
99+ segments : null ,
92100 } ,
93101 conditions : [ {
94102 matcherGroup : {
@@ -135,6 +143,37 @@ const STORED_RBSEGMENTS: Record<string, IRBSegment> = {
135143 }
136144 } ]
137145 } ,
146+ 'excluded_rule_based_segment' : {
147+ name : 'excluded_rule_based_segment' ,
148+ changeNumber : 123 ,
149+ status : 'ACTIVE' ,
150+ conditions : [
151+ {
152+ matcherGroup : {
153+ combiner : 'AND' ,
154+ matchers : [
155+ {
156+ keySelector : null ,
157+ matcherType : 'WHITELIST' ,
158+ negate : false ,
159+ userDefinedSegmentMatcherData : null ,
160+ whitelistMatcherData : {
161+ whitelist : [ 'emi-rule-based@split.io' ]
162+ } ,
163+ unaryNumericMatcherData : null ,
164+ betweenMatcherData : null
165+ }
166+ ]
167+ }
168+ }
169+ ] ,
170+ } ,
171+ 'rule_based_segment_without_conditions' : {
172+ name : 'rule_based_segment_without_conditions' ,
173+ changeNumber : 123 ,
174+ status : 'ACTIVE' ,
175+ conditions : [ ]
176+ }
138177} ;
139178
140179const mockStorageSync = {
@@ -149,6 +188,11 @@ const mockStorageSync = {
149188 return STORED_SEGMENTS [ segmentName ] ? STORED_SEGMENTS [ segmentName ] . has ( matchingKey ) : false ;
150189 }
151190 } ,
191+ largeSegments : {
192+ isInSegment ( segmentName : string , matchingKey : string ) {
193+ return STORED_LARGE_SEGMENTS [ segmentName ] ? STORED_LARGE_SEGMENTS [ segmentName ] . has ( matchingKey ) : false ;
194+ }
195+ } ,
152196 rbSegments : {
153197 get ( rbsegmentName : string ) {
154198 return STORED_RBSEGMENTS [ rbsegmentName ] ;
@@ -168,6 +212,11 @@ const mockStorageAsync = {
168212 return Promise . resolve ( STORED_SEGMENTS [ segmentName ] ? STORED_SEGMENTS [ segmentName ] . has ( matchingKey ) : false ) ;
169213 }
170214 } ,
215+ largeSegments : {
216+ isInSegment ( segmentName : string , matchingKey : string ) {
217+ return Promise . resolve ( STORED_LARGE_SEGMENTS [ segmentName ] ? STORED_LARGE_SEGMENTS [ segmentName ] . has ( matchingKey ) : false ) ;
218+ }
219+ } ,
171220 rbSegments : {
172221 get ( rbsegmentName : string ) {
173222 return Promise . resolve ( STORED_RBSEGMENTS [ rbsegmentName ] ) ;
@@ -190,18 +239,28 @@ describe.each([
190239 value : 'depend_on_mauro_rule_based_segment'
191240 } as IMatcherDto , mockStorage ) ! ;
192241
193- [ matcher , dependentMatcher ] . forEach ( async matcher => {
242+ [ matcher , dependentMatcher ] . forEach ( async ( matcher ) => {
194243
195244 // should return false if the provided key is excluded (even if some condition is met)
196245 let match = matcher ( { key : 'mauro@split.io' , attributes : { location : 'mdp' } } , evaluateFeature ) ;
197246 expect ( thenable ( match ) ) . toBe ( isAsync ) ;
198247 expect ( await match ) . toBe ( false ) ;
199248
200- // should return false if the provided key is in some excluded segment (even if some condition is met)
249+ // should return false if the provided key is in some excluded standard segment (even if some condition is met)
201250 match = matcher ( { key : 'emi@split.io' , attributes : { location : 'tandil' } } , evaluateFeature ) ;
202251 expect ( thenable ( match ) ) . toBe ( isAsync ) ;
203252 expect ( await match ) . toBe ( false ) ;
204253
254+ // should return false if the provided key is in some excluded large segment (even if some condition is met)
255+ match = matcher ( { key : 'emi-large@split.io' , attributes : { location : 'tandil' } } , evaluateFeature ) ;
256+ expect ( thenable ( match ) ) . toBe ( isAsync ) ;
257+ expect ( await match ) . toBe ( false ) ;
258+
259+ // should return false if the provided key is in some excluded rule-based segment (even if some condition is met)
260+ match = matcher ( { key : 'emi-rule-based@split.io' , attributes : { location : 'tandil' } } , evaluateFeature ) ;
261+ expect ( thenable ( match ) ) . toBe ( isAsync ) ;
262+ expect ( await match ) . toBe ( false ) ;
263+
205264 // should return false if doesn't match any condition
206265 match = matcher ( { key : 'zeta@split.io' } , evaluateFeature ) ;
207266 expect ( thenable ( match ) ) . toBe ( isAsync ) ;
@@ -238,6 +297,14 @@ describe.each([
238297
239298 // should support feature flag dependency matcher
240299 expect ( await matcherTrueAlwaysOn ( { key : 'a-key' } , evaluateFeature ) ) . toBe ( true ) ; // Parent split returns one of the expected treatments, so the matcher returns true
300+
301+ const matcherTrueRuleBasedSegmentWithoutConditions = matcherFactory ( loggerMock , {
302+ type : matcherTypes . IN_RULE_BASED_SEGMENT ,
303+ value : 'rule_based_segment_without_conditions'
304+ } as IMatcherDto , mockStorageSync ) ! ;
305+
306+ // should support rule-based segment without conditions
307+ expect ( await matcherTrueRuleBasedSegmentWithoutConditions ( { key : 'a-key' } , evaluateFeature ) ) . toBe ( false ) ;
241308 } ) ;
242309
243310} ) ;
0 commit comments