Skip to content

Commit c68f260

Browse files
authored
New config and methods for iOS (#96)
2 parents 5d0ef4b + c4a99de commit c68f260

File tree

8 files changed

+202
-32
lines changed

8 files changed

+202
-32
lines changed

splitio_ios/example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
platform :ios, '11.0'
2+
platform :ios, '12.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

splitio_ios/example/ios/Podfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PODS:
22
- Flutter (1.0.0)
3-
- Split (2.21.0)
4-
- splitio_ios (0.3.0):
3+
- Split (2.23.0)
4+
- splitio_ios (0.4.0):
55
- Flutter
6-
- Split (~> 2.21.0)
6+
- Split (~> 2.23.0)
77

88
DEPENDENCIES:
99
- Flutter (from `Flutter`)
@@ -21,9 +21,9 @@ EXTERNAL SOURCES:
2121

2222
SPEC CHECKSUMS:
2323
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
24-
Split: e4324a8fe3fcb19c36a9e4fd84a893fc6d4bbeb0
25-
splitio_ios: 8293cb4e46661f9403f92a0d143c5bf6ad5053d4
24+
Split: 8140864905cd12cb66e2cf31e6ba9052d09c086b
25+
splitio_ios: 1c1d7cd88e6756b3b40cf37cdf8610b8720164b0
2626

27-
PODFILE CHECKSUM: 9eb4e99975f80022b373afce31dc8b3feb22df78
27+
PODFILE CHECKSUM: aed42fc5c94ade572556b7ed357c5c57f1bd83a2
2828

2929
COCOAPODS: 1.11.3

splitio_ios/example/ios/SplitTests/SplitClientConfigHelperTests.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class SplitClientConfigHelperTests: XCTestCase {
2121
"ready": 25,
2222
"streamingEnabled": true,
2323
"persistentAttributesEnabled": true,
24-
"syncConfig": ["syncConfigNames": ["split1", "split2"], "syncConfigPrefixes": ["split_", "my_split_"]],
2524
"impressionsMode": "none",
2625
"syncEnabled": false,
2726
"userConsent": "declined",
@@ -89,4 +88,30 @@ class SplitClientConfigHelperTests: XCTestCase {
8988
XCTAssertEqual(expectedImpressionsModes[index].rawValue, config.impressionsMode)
9089
}
9190
}
91+
92+
func testSyncConfigWithoutFlagSetsIsMappedCorrectly() {
93+
let configValues = [
94+
"syncConfig": ["syncConfigNames": ["split1", "split2"], "syncConfigPrefixes": ["split_", "my_split_"]],
95+
]
96+
97+
let splitClientConfig: SplitClientConfig = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
98+
99+
XCTAssertEqual(2, splitClientConfig.sync.filters.count)
100+
XCTAssertEqual(.byName, splitClientConfig.sync.filters[0].type)
101+
XCTAssertEqual(["split1", "split2"], splitClientConfig.sync.filters[0].values)
102+
XCTAssertEqual(.byPrefix, splitClientConfig.sync.filters[1].type)
103+
XCTAssertEqual(["split_", "my_split_"], splitClientConfig.sync.filters[1].values)
104+
}
105+
106+
func testSyncConfigWithFlagSetsIsMappedCorrectly() {
107+
let configValues = [
108+
"syncConfig": ["syncConfigNames": ["split1", "split2"], "syncConfigPrefixes": ["split_", "my_split_"] , "syncConfigFlagSets": ["set_1", "set_2"]],
109+
]
110+
111+
let splitClientConfig: SplitClientConfig = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
112+
113+
XCTAssertEqual(1, splitClientConfig.sync.filters.count)
114+
XCTAssertEqual(.bySet, splitClientConfig.sync.filters[0].type)
115+
XCTAssertEqual(["set_1", "set_2"], splitClientConfig.sync.filters[0].values)
116+
}
92117
}

splitio_ios/example/ios/SplitTests/SplitMethodParserTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ class SplitWrapperStub: SplitWrapper {
328328
var matchingKeyValue = ""
329329
var bucketingKeyValue: String?
330330
var splitNameValue = ""
331+
var flagSetValue = ""
332+
var flagSetsValue: [String] = []
331333
var splitsValue: [String]?
332334
var attributesValue: [String: Any]?
333335
var eventTypeValue: String = ""
@@ -389,6 +391,42 @@ class SplitWrapperStub: SplitWrapper {
389391
return result
390392
}
391393

394+
func getTreatmentsByFlagSet(matchingKey: String, flagSet: String, bucketingKey: String?, attributes: [String : Any]?) -> [String : String] {
395+
matchingKeyValue = matchingKey
396+
bucketingKeyValue = bucketingKey
397+
flagSetValue = flagSet
398+
attributeValue = attributes
399+
400+
return [:]
401+
}
402+
403+
func getTreatmentsByFlagSets(matchingKey: String, flagSets: [String], bucketingKey: String?, attributes: [String : Any]?) -> [String : String] {
404+
matchingKeyValue = matchingKey
405+
bucketingKeyValue = bucketingKey
406+
flagSetsValue = flagSets
407+
attributeValue = attributes
408+
409+
return [:]
410+
}
411+
412+
func getTreatmentsWithConfigByFlagSet(matchingKey: String, flagSet: String, bucketingKey: String?, attributes: [String : Any]?) -> [String : SplitResult] {
413+
matchingKeyValue = matchingKey
414+
bucketingKeyValue = bucketingKey
415+
flagSetValue = flagSet
416+
attributeValue = attributes
417+
418+
return [:]
419+
}
420+
421+
func getTreatmentsWithConfigByFlagSets(matchingKey: String, flagSets: [String], bucketingKey: String?, attributes: [String : Any]?) -> [String : SplitResult] {
422+
matchingKeyValue = matchingKey
423+
bucketingKeyValue = bucketingKey
424+
flagSetsValue = flagSets
425+
attributeValue = attributes
426+
427+
return [:]
428+
}
429+
392430
func track(matchingKey: String, bucketingKey: String?, eventType: String, trafficType: String?, value: Double?, properties: [String: Any]) -> Bool {
393431
matchingKeyValue = matchingKey
394432
bucketingKeyValue = bucketingKey

splitio_ios/example/ios/SplitTests/SplitTests.swift

Lines changed: 76 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class SplitTests: XCTestCase {
1818
splitWrapper.getClient(matchingKey: "key", bucketingKey: "bucketing")
1919
let treatment = splitWrapper.getTreatment(matchingKey: "key", splitName: "split", bucketingKey: "bucketing", attributes: nil)
2020
XCTAssert(treatment != nil)
21-
XCTAssert(client.getTreatmentCalled)
21+
XCTAssert(client.methodCalls["getTreatment"] == true)
2222
}
2323

2424
func testGetTreatments() {
@@ -27,7 +27,7 @@ class SplitTests: XCTestCase {
2727
splitWrapper.getClient(matchingKey: "key", bucketingKey: "bucketing")
2828
let treatment = splitWrapper.getTreatments(matchingKey: "key", splits: ["split"], bucketingKey: "bucketing", attributes: nil)
2929
XCTAssert(!treatment.isEmpty)
30-
XCTAssert(client.getTreatmentsCalled)
30+
XCTAssert(client.methodCalls["getTreatments"] == true)
3131
}
3232

3333
func testGetTreatmentWithConfig() {
@@ -36,7 +36,7 @@ class SplitTests: XCTestCase {
3636
splitWrapper.getClient(matchingKey: "key", bucketingKey: "bucketing")
3737
let treatment = splitWrapper.getTreatmentWithConfig(matchingKey: "key", splitName: "split", bucketingKey: "bucketing", attributes: nil)
3838
XCTAssert(treatment != nil)
39-
XCTAssert(client.getTreatmentWithConfigCalled)
39+
XCTAssert(client.methodCalls["getTreatmentWithConfig"] == true)
4040
}
4141

4242
func testGetTreatmentsWithConfig() {
@@ -45,7 +45,40 @@ class SplitTests: XCTestCase {
4545
splitWrapper.getClient(matchingKey: "key", bucketingKey: "bucketing")
4646
let treatment = splitWrapper.getTreatmentsWithConfig(matchingKey: "key", splits: ["split"], bucketingKey: "bucketing", attributes: nil)
4747
XCTAssert(!treatment.isEmpty)
48-
XCTAssert(client.getTreatmentsWithConfigCalled)
48+
XCTAssert(client.methodCalls["getTreatmentsWithConfig"] == true)
49+
}
50+
51+
func testGetTreatmentsByFlagSet() {
52+
let client = SplitClientStub()
53+
splitWrapper = DefaultSplitWrapper(splitFactoryProvider: SplitFactoryProviderStubWithClient(client: client))
54+
splitWrapper.getClient(matchingKey: "key", bucketingKey: "bucketing")
55+
let treatment = splitWrapper.getTreatmentsByFlagSet(matchingKey: "key", flagSet: "set_1", bucketingKey: "bucketing", attributes: nil)
56+
XCTAssert(client.methodCalls["getTreatmentsByFlagSet"] == true)
57+
}
58+
59+
func testGetTreatmentsByFlagSets() {
60+
let client = SplitClientStub()
61+
splitWrapper = DefaultSplitWrapper(splitFactoryProvider: SplitFactoryProviderStubWithClient(client: client))
62+
splitWrapper.getClient(matchingKey: "key", bucketingKey: "bucketing")
63+
let treatment = splitWrapper.getTreatmentsByFlagSets(matchingKey: "key", flagSets: ["set_1"], bucketingKey: "bucketing", attributes: nil)
64+
XCTAssert(client.methodCalls["getTreatmentsByFlagSets"] == true)
65+
}
66+
67+
func testGetTreatmentsWithConfigByFlagSet() {
68+
let client = SplitClientStub()
69+
splitWrapper = DefaultSplitWrapper(splitFactoryProvider: SplitFactoryProviderStubWithClient(client: client))
70+
splitWrapper.getClient(matchingKey: "key", bucketingKey: "bucketing")
71+
let treatment = splitWrapper.getTreatmentsWithConfigByFlagSet(matchingKey: "key", flagSet: "set_1", bucketingKey: "bucketing", attributes: nil)
72+
XCTAssert(client.methodCalls["getTreatmentsWithConfigByFlagSet"] == true)
73+
}
74+
75+
func testGetTreatmentsWithConfigByFlagSets() {
76+
let client = SplitClientStub()
77+
splitWrapper = DefaultSplitWrapper(splitFactoryProvider: SplitFactoryProviderStubWithClient(client: client))
78+
splitWrapper.getClient(matchingKey: "key", bucketingKey: "bucketing")
79+
let treatment = splitWrapper.getTreatmentsWithConfigByFlagSets(matchingKey: "key", flagSets: ["set_1"], bucketingKey: "bucketing", attributes: nil)
80+
81+
XCTAssert(client.methodCalls["getTreatmentsWithConfigByFlagSets"] == true)
4982
}
5083

5184
func testTrack() {
@@ -146,7 +179,7 @@ class SplitTests: XCTestCase {
146179
usedKeys.insert(Key(matchingKey: "key", bucketingKey: "bucketing"))
147180
splitWrapper = DefaultSplitWrapper(splitFactoryProvider: SplitFactoryProviderStubWithClient(client: client), usedKeys: usedKeys)
148181
splitWrapper.flush(matchingKey: "key", bucketingKey: "bucketing")
149-
XCTAssert(client.flushCalled)
182+
XCTAssert((client.methodCalls["flush"] != nil))
150183
}
151184

152185
func testDestroy() {
@@ -303,11 +336,17 @@ class SplitFactoryStub: SplitFactory {
303336
class SplitClientStub: SplitClient {
304337

305338
var destroyCalled: Bool = false
306-
var getTreatmentCalled: Bool = false
307-
var getTreatmentWithConfigCalled: Bool = false
308-
var getTreatmentsCalled: Bool = false
309-
var getTreatmentsWithConfigCalled: Bool = false
310-
var flushCalled: Bool = false
339+
var methodCalls = [
340+
"getTreatment": false,
341+
"getTreatmentWithConfig": false,
342+
"getTreatments": false,
343+
"getTreatmentsWithConfig": false,
344+
"getTreatmentsByFlagSet": false,
345+
"getTreatmentsByFlagSets": false,
346+
"getTreatmentsWithConfigByFlagSet": false,
347+
"getTreatmentsWithConfigByFlagSets": false,
348+
"flush": false,
349+
]
311350
var eventTypeValue: String = ""
312351
var trafficTypeValue: String?
313352
var valueValue: Double?
@@ -319,35 +358,55 @@ class SplitClientStub: SplitClient {
319358
var sdkReadyEventAction: SplitAction?
320359

321360
func getTreatment(_ split: String, attributes: [String: Any]?) -> String {
322-
getTreatmentCalled = true
361+
methodCalls["getTreatment"] = true
323362
return SplitConstants.control
324363
}
325364

326365
func getTreatment(_ split: String) -> String {
327-
getTreatmentCalled = true
366+
methodCalls["getTreatment"] = true
328367
return SplitConstants.control
329368
}
330369

331370
func getTreatments(splits: [String], attributes: [String: Any]?) -> [String: String] {
332-
getTreatmentsCalled = true
371+
methodCalls["getTreatments"] = true
333372
return ["feature": SplitConstants.control]
334373
}
335374

336375
func getTreatmentWithConfig(_ split: String) -> SplitResult {
337-
getTreatmentWithConfigCalled = true
376+
methodCalls["getTreatmentWithConfig"] = true
338377
return SplitResult(treatment: SplitConstants.control)
339378
}
340379

341380
func getTreatmentWithConfig(_ split: String, attributes: [String: Any]?) -> SplitResult {
342-
getTreatmentWithConfigCalled = true
381+
methodCalls["getTreatmentWithConfig"] = true
343382
return SplitResult(treatment: SplitConstants.control)
344383
}
345384

346385
func getTreatmentsWithConfig(splits: [String], attributes: [String: Any]?) -> [String: SplitResult] {
347-
getTreatmentsWithConfigCalled = true
386+
methodCalls["getTreatmentsWithConfig"] = true
348387
return ["feature": SplitResult(treatment: SplitConstants.control)]
349388
}
350389

390+
func getTreatmentsByFlagSet(_ flagSet: String, attributes: [String : Any]?) -> [String : String] {
391+
methodCalls["getTreatmentsByFlagSet"] = true
392+
return [:]
393+
}
394+
395+
func getTreatmentsByFlagSets(_ flagSets: [String], attributes: [String : Any]?) -> [String : String] {
396+
methodCalls["getTreatmentsByFlagSets"] = true
397+
return [:]
398+
}
399+
400+
func getTreatmentsWithConfigByFlagSet(_ flagSet: String, attributes: [String : Any]?) -> [String : SplitResult] {
401+
methodCalls["getTreatmentsWithConfigByFlagSet"] = true
402+
return [:]
403+
}
404+
405+
func getTreatmentsWithConfigByFlagSets(_ flagSets: [String], attributes: [String : Any]?) -> [String : SplitResult] {
406+
methodCalls["getTreatmentsWithConfigByFlagSets"] = true
407+
return [:]
408+
}
409+
351410
func on(event: SplitEvent, execute action: @escaping SplitAction) {
352411
if event == SplitEvent.sdkReady {
353412
sdkReadyEventAction = action
@@ -430,7 +489,7 @@ class SplitClientStub: SplitClient {
430489
}
431490

432491
func flush() {
433-
flushCalled = true
492+
methodCalls["flush"] = true
434493
}
435494

436495
func destroy() {

splitio_ios/ios/Classes/SplitClientConfigHelper.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class SplitClientConfigHelper {
2424
static private let SYNC_CONFIG = "syncConfig"
2525
static private let SYNC_CONFIG_NAMES = "syncConfigNames"
2626
static private let SYNC_CONFIG_PREFIXES = "syncConfigPrefixes"
27+
static private let SYNC_CONFIG_SETS = "syncConfigFlagSets"
2728
static private let IMPRESSIONS_MODE = "impressionsMode"
2829
static private let SYNC_ENABLED = "syncEnabled"
2930
static private let USER_CONSENT = "userConsent"
@@ -149,12 +150,19 @@ class SplitClientConfigHelper {
149150
if configurationMap[SYNC_CONFIG] != nil {
150151
if let syncConfig = configurationMap[SYNC_CONFIG] as? [String: [String]] {
151152
let syncConfigBuilder = SyncConfig.builder()
152-
if let syncNames = syncConfig[SYNC_CONFIG_NAMES] as? [String] {
153-
syncConfigBuilder.addSplitFilter(SplitFilter.byName(syncNames))
154-
}
155153

156-
if let syncPrefixes = syncConfig[SYNC_CONFIG_NAMES] as? [String] {
157-
syncConfigBuilder.addSplitFilter(SplitFilter.byPrefix(syncPrefixes))
154+
if (syncConfig[SYNC_CONFIG_SETS] != nil && syncConfig[SYNC_CONFIG_SETS]?.isEmpty == false) {
155+
if let syncFlagSets = syncConfig[SYNC_CONFIG_SETS] as? [String] {
156+
syncConfigBuilder.addSplitFilter(SplitFilter.bySet(syncFlagSets))
157+
}
158+
} else {
159+
if let syncNames = syncConfig[SYNC_CONFIG_NAMES] as? [String] {
160+
syncConfigBuilder.addSplitFilter(SplitFilter.byName(syncNames))
161+
}
162+
163+
if let syncPrefixes = syncConfig[SYNC_CONFIG_PREFIXES] as? [String] {
164+
syncConfigBuilder.addSplitFilter(SplitFilter.byPrefix(syncPrefixes))
165+
}
158166
}
159167

160168
config.sync = syncConfigBuilder.build()

splitio_ios/ios/Classes/SplitWrapper.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ protocol EvaluationWrapper {
3131
func getTreatmentWithConfig(matchingKey: String, splitName: String, bucketingKey: String?, attributes: [String: Any]?) -> SplitResult?
3232

3333
func getTreatmentsWithConfig(matchingKey: String, splits: [String], bucketingKey: String?, attributes: [String: Any]?) -> [String: SplitResult]
34+
35+
func getTreatmentsByFlagSet(matchingKey: String, flagSet: String, bucketingKey: String?, attributes: [String: Any]?) -> [String: String]
36+
37+
func getTreatmentsByFlagSets(matchingKey: String, flagSets: [String], bucketingKey: String?, attributes: [String: Any]?) -> [String: String]
38+
39+
func getTreatmentsWithConfigByFlagSet(matchingKey: String, flagSet: String, bucketingKey: String?, attributes: [String: Any]?) -> [String: SplitResult]
40+
41+
func getTreatmentsWithConfigByFlagSets(matchingKey: String, flagSets: [String], bucketingKey: String?, attributes: [String: Any]?) -> [String: SplitResult]
3442
}
3543

3644
protocol AttributesWrapper {
@@ -121,6 +129,38 @@ class DefaultSplitWrapper: SplitWrapper {
121129
return client.getTreatmentsWithConfig(splits: splits, attributes: attributes)
122130
}
123131

132+
func getTreatmentsByFlagSet(matchingKey: String, flagSet: String, bucketingKey: String? = nil, attributes: [String: Any]? = [:]) -> [String: String] {
133+
guard let client = getInitializedClient(matchingKey: matchingKey, bucketingKey: bucketingKey) else {
134+
return [:]
135+
}
136+
137+
return client.getTreatmentsByFlagSet(flagSet, attributes: attributes)
138+
}
139+
140+
func getTreatmentsByFlagSets(matchingKey: String, flagSets: [String], bucketingKey: String? = nil, attributes: [String: Any]? = [:]) -> [String: String] {
141+
guard let client = getInitializedClient(matchingKey: matchingKey, bucketingKey: bucketingKey) else {
142+
return [:]
143+
}
144+
145+
return client.getTreatmentsByFlagSets(flagSets, attributes: attributes)
146+
}
147+
148+
func getTreatmentsWithConfigByFlagSet(matchingKey: String, flagSet: String, bucketingKey: String? = nil, attributes: [String: Any]? = [:]) -> [String: SplitResult] {
149+
guard let client = getInitializedClient(matchingKey: matchingKey, bucketingKey: bucketingKey) else {
150+
return [:]
151+
}
152+
153+
return client.getTreatmentsWithConfigByFlagSet(flagSet, attributes: attributes)
154+
}
155+
156+
func getTreatmentsWithConfigByFlagSets(matchingKey: String, flagSets: [String], bucketingKey: String? = nil, attributes: [String: Any]? = [:]) -> [String: SplitResult] {
157+
guard let client = getInitializedClient(matchingKey: matchingKey, bucketingKey: bucketingKey) else {
158+
return [:]
159+
}
160+
161+
return client.getTreatmentsWithConfigByFlagSets(flagSets, attributes: attributes)
162+
}
163+
124164
func track(matchingKey: String, bucketingKey: String?, eventType: String, trafficType: String?, value: Double?, properties: [String: Any]) -> Bool {
125165
guard let client = getInitializedClient(matchingKey: matchingKey, bucketingKey: bucketingKey) else {
126166
return false

0 commit comments

Comments
 (0)