File tree Expand file tree Collapse file tree 2 files changed +31
-7
lines changed
src/sync/polling/updaters Expand file tree Collapse file tree 2 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { telemetryTrackerFactory } from '../../../../trackers/telemetryTracker';
1414import { splitNotifications } from '../../../streaming/__tests__/dataMocks' ;
1515import { RBSegmentsCacheInMemory } from '../../../../storages/inMemory/RBSegmentsCacheInMemory' ;
1616import { RB_SEGMENT_UPDATE , SPLIT_UPDATE } from '../../../streaming/constants' ;
17+ import { IN_RULE_BASED_SEGMENT } from '../../../../utils/constants' ;
1718
1819const ARCHIVED_FF = 'ARCHIVED' ;
1920
@@ -84,13 +85,31 @@ const testFFEmptySet: ISplit =
8485 conditions : [ ] ,
8586 sets : [ ]
8687} ;
88+ // @ts -ignore
89+ const rbsWithExcludedSegment : IRBSegment = {
90+ name : 'rbs' ,
91+ status : 'ACTIVE' ,
92+ conditions : [ ] ,
93+ excluded : {
94+ segments : [ {
95+ type : 'standard' ,
96+ name : 'C'
97+ } , {
98+ type : 'rule-based' ,
99+ name : 'D'
100+ } ]
101+ }
102+ } ;
87103
88104test ( 'splitChangesUpdater / segments parser' , ( ) => {
105+ let segments = parseSegments ( activeSplitWithSegments as ISplit ) ;
106+ expect ( segments ) . toEqual ( new Set ( [ 'A' , 'B' ] ) ) ;
89107
90- const segments = parseSegments ( activeSplitWithSegments as ISplit ) ;
108+ segments = parseSegments ( rbsWithExcludedSegment ) ;
109+ expect ( segments ) . toEqual ( new Set ( [ 'C' ] ) ) ;
91110
92- expect ( segments . has ( 'A' ) ) . toBe ( true ) ;
93- expect ( segments . has ( 'B' ) ) . toBe ( true ) ;
111+ segments = parseSegments ( rbsWithExcludedSegment , IN_RULE_BASED_SEGMENT ) ;
112+ expect ( segments ) . toEqual ( new Set ( [ 'D' ] ) ) ;
94113} ) ;
95114
96115test ( 'splitChangesUpdater / compute splits mutation' , ( ) => {
Original file line number Diff line number Diff line change @@ -26,15 +26,20 @@ function checkAllSegmentsExist(segments: ISegmentsCacheBase): Promise<boolean> {
2626}
2727
2828/**
29- * Collect segments from a raw split definition.
29+ * Collect segments from a raw FF or RBS definition.
3030 * Exported for testing purposes.
3131 */
3232export function parseSegments ( ruleEntity : ISplit | IRBSegment , matcherType : typeof IN_SEGMENT | typeof IN_RULE_BASED_SEGMENT = IN_SEGMENT ) : Set < string > {
3333 const { conditions = [ ] , excluded } = ruleEntity as IRBSegment ;
3434
35- const segments = new Set < string > (
36- excluded && excluded . segments ? excluded . segments . map ( segment => segment . name ) : [ ]
37- ) ;
35+ const segments = new Set < string > ( ) ;
36+ if ( excluded && excluded . segments ) {
37+ excluded . segments . forEach ( ( { type, name } ) => {
38+ if ( ( type === 'standard' && matcherType === IN_SEGMENT ) || ( type === 'rule-based' && matcherType === IN_RULE_BASED_SEGMENT ) ) {
39+ segments . add ( name ) ;
40+ }
41+ } ) ;
42+ }
3843
3944 for ( let i = 0 ; i < conditions . length ; i ++ ) {
4045 const matchers = conditions [ i ] . matcherGroup . matchers ;
You can’t perform that action at this time.
0 commit comments