88 let ( :flag_sets_repository ) { SplitIoClient ::Cache ::Repositories ::MemoryFlagSetsRepository . new ( [ ] ) }
99 let ( :flag_set_filter ) { SplitIoClient ::Cache ::Filter ::FlagSetsFilter . new ( [ ] ) }
1010 let ( :splits_repository ) { SplitIoClient ::Cache ::Repositories ::SplitsRepository . new ( config , flag_sets_repository , flag_set_filter ) }
11- let ( :evaluator ) { SplitIoClient ::Engine ::Parser ::Evaluator . new ( segments_repository , splits_repository , true ) }
12-
1311
1412 context '#string_type' do
1513 it 'is not string type matcher' do
16- expect ( described_class . new ( nil , nil , nil , config , nil ) . string_type? ) . to be false
14+ expect ( described_class . new ( nil , nil , nil , config ) . string_type? ) . to be false
1715 end
1816 end
1917
2018 context 'test_matcher' do
2119 it 'return false if excluded key is passed' do
2220 rbs_repositoy = SplitIoClient ::Cache ::Repositories ::RuleBasedSegmentsRepository . new ( config )
2321 rbs_repositoy . update ( [ { name : 'foo' , trafficTypeName : 'tt_name_1' , conditions : [ ] , excluded : { keys : [ 'key1' ] , segments : [ ] } } ] , [ ] , -1 )
24- matcher = described_class . new ( rbs_repositoy , segments_repository , 'foo' , config , nil )
22+ matcher = described_class . new ( segments_repository , rbs_repositoy , 'foo' , config )
2523 expect ( matcher . match? ( value : 'key1' ) ) . to be false
2624 end
2725
2826 it 'return false if excluded segment is passed' do
2927 rbs_repositoy = SplitIoClient ::Cache ::Repositories ::RuleBasedSegmentsRepository . new ( config )
28+ evaluator = SplitIoClient ::Engine ::Parser ::Evaluator . new ( segments_repository , splits_repository , rbs_repositoy , true )
3029 segments_repository . add_to_segment ( { :name => 'segment1' , :added => [ ] , :removed => [ ] } )
31- rbs_repositoy . update ( [ { name : 'foo' , trafficTypeName : 'tt_name_1' , conditions : [ ] , excluded : { keys : [ 'key1' ] , segments : [ 'segment1' ] } } ] , [ ] , -1 )
32- matcher = described_class . new ( rbs_repositoy , segments_repository , 'foo' , config , nil )
30+ rbs_repositoy . update ( [ { :name => 'foo' , :trafficTypeName => 'tt_name_1' , :conditions => [ ] , :excluded => { :keys => [ 'key1' ] , :segments => [ { :name => 'segment1' , :type => 'standard' } ] } } ] , [ ] , -1 )
31+ matcher = described_class . new ( segments_repository , rbs_repositoy , 'foo' , config )
3332 expect ( matcher . match? ( value : 'key2' ) ) . to be false
3433 end
3534
35+ it 'return true if excluded rb segment is matched' do
36+ rbs_repositoy = SplitIoClient ::Cache ::Repositories ::RuleBasedSegmentsRepository . new ( config )
37+ rbs = { :name => 'sample_rule_based_segment' , :trafficTypeName => 'tt_name_1' , :conditions => [ ] , :excluded => { :keys => [ ] , :segments => [ { :name => 'no_excludes' , :type => 'rule-based' } ] } }
38+ rbs2 = { :name => 'no_excludes' , :trafficTypeName => 'tt_name_1' ,
39+ :conditions => [ {
40+ :matcherGroup => {
41+ :combiner => "AND" ,
42+ :matchers => [
43+ {
44+ :keySelector => {
45+ :trafficType => "user" ,
46+ :attribute => "email"
47+ } ,
48+ :matcherType => "ENDS_WITH" ,
49+ :negate => false ,
50+ :whitelistMatcherData => {
51+ :whitelist => [
52+ "@split.io"
53+ ]
54+ }
55+ }
56+ ]
57+ }
58+ }
59+ ] , :excluded => { :keys => [ ] , :segments => [ ] } }
60+
61+ rbs_repositoy . update ( [ rbs , rbs2 ] , [ ] , -1 )
62+ matcher = described_class . new ( segments_repository , rbs_repositoy , 'sample_rule_based_segment' , config )
63+ expect ( matcher . match? ( value : 'bilal@split.io' , attributes : { 'email' : 'bilal@split.io' } ) ) . to be true
64+ expect ( matcher . match? ( value : 'bilal' , attributes : { 'email' : 'bilal' } ) ) . to be false
65+ end
66+
3667 it 'return true if condition matches' do
3768 rule_based_segment = { :name => 'corge' , :trafficTypeName => 'tt_name_5' ,
3869 :excluded => { :keys => [ ] , :segments => [ ] } ,
5889
5990 rbs_repositoy = SplitIoClient ::Cache ::Repositories ::RuleBasedSegmentsRepository . new ( config )
6091 rbs_repositoy . update ( [ rule_based_segment ] , [ ] , -1 )
61- matcher = described_class . new ( rbs_repositoy , segments_repository , 'corge' , config , evaluator )
92+ matcher = described_class . new ( segments_repository , rbs_repositoy , 'corge' , config )
6293 expect ( matcher . match? ( { :matching_key => 'user' , :attributes => { } } ) ) . to be false
6394 expect ( matcher . match? ( { :matching_key => 'k1' , :attributes => { } } ) ) . to be true
6495 end
96+
97+ it 'return true if dependent rb segment matches' do
98+ rbs_repositoy = SplitIoClient ::Cache ::Repositories ::RuleBasedSegmentsRepository . new ( config )
99+ rbs = {
100+ :changeNumber => 5 ,
101+ :name => "dependent_rbs" ,
102+ :status => "ACTIVE" ,
103+ :trafficTypeName => "user" ,
104+ :excluded => { :keys => [ "mauro@split.io" , "gaston@split.io" ] , :segments => [ ] } ,
105+ :conditions => [
106+ {
107+ :matcherGroup => {
108+ :combiner => "AND" ,
109+ :matchers => [
110+ {
111+ :keySelector => {
112+ :trafficType => "user" ,
113+ :attribute => "email"
114+ } ,
115+ :matcherType => "ENDS_WITH" ,
116+ :negate => false ,
117+ :whitelistMatcherData => {
118+ :whitelist => [
119+ "@split.io"
120+ ]
121+ }
122+ }
123+ ]
124+ }
125+ }
126+ ] }
127+ rbs2 = {
128+ :changeNumber => 5 ,
129+ :name => "sample_rule_based_segment" ,
130+ :status => "ACTIVE" ,
131+ :trafficTypeName => "user" ,
132+ :excluded => {
133+ :keys => [ ] ,
134+ :segments => [ ]
135+ } ,
136+ :conditions => [
137+ {
138+ :conditionType => "ROLLOUT" ,
139+ :matcherGroup => {
140+ :combiner => "AND" ,
141+ :matchers => [
142+ {
143+ :keySelector => {
144+ :trafficType => "user"
145+ } ,
146+ :matcherType => "IN_RULE_BASED_SEGMENT" ,
147+ :negate => false ,
148+ :userDefinedSegmentMatcherData => {
149+ :segmentName => "dependent_rbs"
150+ }
151+ }
152+ ]
153+ }
154+ }
155+ ]
156+ }
157+ rbs_repositoy . update ( [ rbs , rbs2 ] , [ ] , -1 )
158+ matcher = described_class . new ( segments_repository , rbs_repositoy , 'sample_rule_based_segment' , config )
159+ expect ( matcher . match? ( value : 'bilal@split.io' , attributes : { 'email' : 'bilal@split.io' } ) ) . to be true
160+ expect ( matcher . match? ( value : 'bilal' , attributes : { 'email' : 'bilal' } ) ) . to be false
161+ end
65162 end
66163end
0 commit comments