@@ -20,15 +20,50 @@ import XCTest
20
20
// MARK: - Sample Data
21
21
22
22
class HoldoutTests : XCTestCase {
23
+ static var variationData : [ String : Any ] = [ " id " : " 553339214 " ,
24
+ " key " : " house " ,
25
+ " featureEnabled " : true ,
26
+ " variables " : [ [ " id " : " 553339214 " , " value " : " 100 " ] ] ]
27
+
28
+ static var trafficAllocationData : [ String : Any ] = [ " entityId " : " 553339214 " , " endOfRange " : 5000 ]
29
+
30
+ static var conditionHolderData : [ Any ] = [ " or " , [ " name " : " geo " ,
31
+ " type " : " custom_attribute " ,
32
+ " match " : " exact " ,
33
+ " value " : 30 ] ]
34
+
23
35
/// Global holoout without included and excluded key
24
36
static var sampleData : [ String : Any ] = [ " id " : " 11111 " ,
25
37
" key " : " background " ,
26
38
" status " : " Running " ,
27
39
" layerId " : " 22222 " ,
28
- " variations " : [ VariationTests . sampleData] ,
29
- " trafficAllocation " : [ TrafficAllocationTests . sampleData] ,
40
+ " variations " : [ HoldoutTests . variationData] ,
41
+ " trafficAllocation " : [ HoldoutTests . trafficAllocationData] ,
42
+ " audienceIds " : [ " 33333 " ] ,
43
+ " audienceConditions " : HoldoutTests . conditionHolderData]
44
+
45
+ static var sampleDataWithIncludedFlags : [ String : Any ] = [ " id " : " 11111 " ,
46
+ " key " : " background " ,
47
+ " status " : " Running " ,
48
+ " layerId " : " 22222 " ,
49
+ " variations " : [ HoldoutTests . variationData] ,
50
+ " trafficAllocation " : [ HoldoutTests . trafficAllocationData] ,
30
51
" audienceIds " : [ " 33333 " ] ,
31
- " audienceConditions " : ConditionHolderTests . sampleData]
52
+ " audienceConditions " : HoldoutTests . conditionHolderData,
53
+ " includedFlags " : [ " 4444 " , " 5555 " ] ]
54
+
55
+ static var sampleDataWithIncludedAndExcludedFlags : [ String : Any ] = [ " id " : " 11111 " ,
56
+ " key " : " background " ,
57
+ " status " : " Running " ,
58
+ " layerId " : " 22222 " ,
59
+ " variations " : [ HoldoutTests . variationData] ,
60
+ " trafficAllocation " : [ HoldoutTests . trafficAllocationData] ,
61
+ " audienceIds " : [ " 33333 " ] ,
62
+ " audienceConditions " : HoldoutTests . conditionHolderData,
63
+ " includedFlags " : [ " 4444 " , " 5555 " ] ,
64
+ " excludedFlags " : [ " 8888 " , " 9999 " ] ]
65
+
66
+
32
67
33
68
}
34
69
@@ -44,44 +79,43 @@ extension HoldoutTests {
44
79
XCTAssert ( model. key == " background " )
45
80
XCTAssert ( model. status == . running)
46
81
XCTAssert ( model. layerId == " 22222 " )
47
- XCTAssert ( model. variations == [ try ! OTUtils . model ( from: VariationTests . sampleData ) ] )
48
- XCTAssert ( model. trafficAllocation == [ try ! OTUtils . model ( from: TrafficAllocationTests . sampleData ) ] )
82
+ XCTAssert ( model. variations == [ try ! OTUtils . model ( from: HoldoutTests . variationData ) ] )
83
+ XCTAssert ( model. trafficAllocation == [ try ! OTUtils . model ( from: HoldoutTests . trafficAllocationData ) ] )
49
84
XCTAssert ( model. audienceIds == [ " 33333 " ] )
50
- XCTAssert ( model. audienceConditions == ( try ! OTUtils . model ( from: ConditionHolderTests . sampleData ) ) )
85
+ XCTAssert ( model. audienceConditions == ( try ! OTUtils . model ( from: HoldoutTests . conditionHolderData ) ) )
51
86
}
52
87
53
88
func testDecodeSuccessWithIncludedFlags( ) {
54
- var data : [ String : Any ] = HoldoutTests . sampleData
55
- data [ " includedFlags " ] = [ " 4444 " , " 5555 " ]
89
+ let data : [ String : Any ] = HoldoutTests . sampleDataWithIncludedFlags
56
90
57
91
let model : Holdout = try ! OTUtils . model ( from: data)
58
92
59
93
XCTAssert ( model. id == " 11111 " )
60
94
XCTAssert ( model. key == " background " )
61
95
XCTAssert ( model. status == . running)
62
96
XCTAssert ( model. layerId == " 22222 " )
63
- XCTAssert ( model. variations == [ try ! OTUtils . model ( from: VariationTests . sampleData ) ] )
64
- XCTAssert ( model. trafficAllocation == [ try ! OTUtils . model ( from: TrafficAllocationTests . sampleData ) ] )
97
+ XCTAssert ( model. variations == [ try ! OTUtils . model ( from: HoldoutTests . variationData ) ] )
98
+ XCTAssert ( model. trafficAllocation == [ try ! OTUtils . model ( from: HoldoutTests . trafficAllocationData ) ] )
65
99
XCTAssert ( model. audienceIds == [ " 33333 " ] )
66
- XCTAssert ( model. audienceConditions == ( try ! OTUtils . model ( from: ConditionHolderTests . sampleData ) ) )
100
+ XCTAssert ( model. audienceConditions == ( try ! OTUtils . model ( from: HoldoutTests . conditionHolderData ) ) )
67
101
XCTAssertEqual ( model. includedFlags, [ " 4444 " , " 5555 " ] )
68
102
}
69
103
70
- func testDecodeSuccessWithExcludedFlags( ) {
71
- var data : [ String : Any ] = HoldoutTests . sampleData
72
- data [ " excludedFlags " ] = [ " 4444 " , " 5555 " ]
104
+ func testDecodeSuccessWithIncludedAndExcludedFlags( ) {
105
+ let data : [ String : Any ] = HoldoutTests . sampleDataWithIncludedAndExcludedFlags
73
106
74
107
let model : Holdout = try ! OTUtils . model ( from: data)
75
108
76
109
XCTAssert ( model. id == " 11111 " )
77
110
XCTAssert ( model. key == " background " )
78
111
XCTAssert ( model. status == . running)
79
112
XCTAssert ( model. layerId == " 22222 " )
80
- XCTAssert ( model. variations == [ try ! OTUtils . model ( from: VariationTests . sampleData ) ] )
81
- XCTAssert ( model. trafficAllocation == [ try ! OTUtils . model ( from: TrafficAllocationTests . sampleData ) ] )
113
+ XCTAssert ( model. variations == [ try ! OTUtils . model ( from: HoldoutTests . variationData ) ] )
114
+ XCTAssert ( model. trafficAllocation == [ try ! OTUtils . model ( from: HoldoutTests . trafficAllocationData ) ] )
82
115
XCTAssert ( model. audienceIds == [ " 33333 " ] )
83
- XCTAssert ( model. audienceConditions == ( try ! OTUtils . model ( from: ConditionHolderTests . sampleData) ) )
84
- XCTAssertEqual ( model. excludedFlags, [ " 4444 " , " 5555 " ] )
116
+ XCTAssert ( model. audienceConditions == ( try ! OTUtils . model ( from: HoldoutTests . conditionHolderData) ) )
117
+ XCTAssertEqual ( model. includedFlags, [ " 4444 " , " 5555 " ] )
118
+ XCTAssertEqual ( model. excludedFlags, [ " 8888 " , " 9999 " ] )
85
119
}
86
120
87
121
@@ -95,8 +129,8 @@ extension HoldoutTests {
95
129
XCTAssert ( model. key == " background " )
96
130
XCTAssert ( model. status == . running)
97
131
XCTAssert ( model. layerId == " 22222 " )
98
- XCTAssert ( model. variations == [ try ! OTUtils . model ( from: VariationTests . sampleData ) ] )
99
- XCTAssert ( model. trafficAllocation == [ try ! OTUtils . model ( from: TrafficAllocationTests . sampleData ) ] )
132
+ XCTAssert ( model. variations == [ try ! OTUtils . model ( from: HoldoutTests . variationData ) ] )
133
+ XCTAssert ( model. trafficAllocation == [ try ! OTUtils . model ( from: HoldoutTests . trafficAllocationData ) ] )
100
134
XCTAssert ( model. audienceIds == [ " 33333 " ] )
101
135
}
102
136
@@ -172,8 +206,8 @@ extension HoldoutTests {
172
206
" key " : " background " ,
173
207
" status " : " Running " ,
174
208
" layerId " : " 22222 " ,
175
- " variations " : [ VariationTests . sampleData ] ,
176
- " trafficAllocation " : [ TrafficAllocationTests . sampleData ] ,
209
+ " variations " : [ HoldoutTests . variationData ] ,
210
+ " trafficAllocation " : [ HoldoutTests . trafficAllocationData ] ,
177
211
" audienceIds " : [ ] ,
178
212
" audienceConditions " : [ ] ,
179
213
" forcedVariations " : [ " 12345 " : " 1234567890 " ] ]
0 commit comments