Skip to content

Commit 286d26a

Browse files
committed
New configs in ios (#65)
1 parent 54ee104 commit 286d26a

File tree

5 files changed

+135
-26
lines changed

5 files changed

+135
-26
lines changed

splitio_ios/example/ios/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PODS:
22
- Flutter (1.0.0)
3-
- Split (2.15.0)
4-
- splitio_ios (0.1.0):
3+
- Split (2.20.1)
4+
- splitio_ios (0.2.0):
55
- Flutter
6-
- Split (~> 2.15.0)
6+
- Split (~> 2.20.1)
77

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

2222
SPEC CHECKSUMS:
2323
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
24-
Split: d103c6afa47b5d1eac21e066c6bc09c879b21798
25-
splitio_ios: 665651004a4984a415386b1eed4ae315b50bc069
24+
Split: afbdfda76fe2c90bd449564eed2d83de00c0ff69
25+
splitio_ios: e6d3dfe108ba894129a6b249d8914e3c44f0ffc4
2626

2727
PODFILE CHECKSUM: 6ab177d3659abbf5f15e864674366127c98cb8c0
2828

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
import XCTest
22
@testable import splitio_ios
3+
@testable import Split
34

45
class SplitClientConfigHelperTests: XCTestCase {
56

67
func testConfigValuesAreMappedCorrectly() throws {
78
let configValues: [String: Any?] = ["featuresRefreshRate": 80000,
8-
"segmentsRefreshRate": 70000,
9-
"impressionsRefreshRate": 60000,
10-
"telemetryRefreshRate": 2000,
11-
"eventsQueueSize": 3999,
12-
"impressionsQueueSize": 2999,
13-
"eventFlushInterval": 40000,
14-
"eventsPerPush": 5000,
15-
"trafficType": "none",
16-
"connectionTimeOut": 10,
17-
"readTimeout": 25,
18-
"disableLabels": true,
19-
"enableDebug": true,
20-
"proxyHost": "https://proxy",
21-
"ready": 25,
22-
"streamingEnabled": true,
23-
"persistentAttributesEnabled": true,
24-
"syncConfig": ["syncConfigNames": ["split1", "split2"], "syncConfigPrefixes": ["split_", "my_split_"]]]
9+
"segmentsRefreshRate": 70000,
10+
"impressionsRefreshRate": 60000,
11+
"telemetryRefreshRate": 2000,
12+
"eventsQueueSize": 3999,
13+
"impressionsQueueSize": 2999,
14+
"eventFlushInterval": 40000,
15+
"eventsPerPush": 5000,
16+
"trafficType": "none",
17+
"connectionTimeOut": 10,
18+
"readTimeout": 25,
19+
"disableLabels": true,
20+
"proxyHost": "https://proxy",
21+
"ready": 25,
22+
"streamingEnabled": true,
23+
"persistentAttributesEnabled": true,
24+
"syncConfig": ["syncConfigNames": ["split1", "split2"], "syncConfigPrefixes": ["split_", "my_split_"]],
25+
"impressionsMode": "none",
26+
"syncEnabled": false,
27+
"userConsent": "declined",
28+
"encryptionEnabled": true,
29+
"logLevel": "verbose"
30+
]
2531

2632
let splitClientConfig = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
2733

@@ -34,8 +40,51 @@ class SplitClientConfigHelperTests: XCTestCase {
3440
XCTAssert(40000 == splitClientConfig.eventsPushRate)
3541
XCTAssert(5000 == splitClientConfig.eventsPerPush)
3642
XCTAssert("none" == splitClientConfig.trafficType)
37-
XCTAssert(splitClientConfig.isDebugModeEnabled)
3843
XCTAssert(splitClientConfig.streamingEnabled)
3944
XCTAssert(splitClientConfig.persistentAttributesEnabled)
45+
XCTAssertEqual("NONE", splitClientConfig.impressionsMode)
46+
XCTAssertFalse(splitClientConfig.syncEnabled)
47+
XCTAssertEqual(.declined, splitClientConfig.userConsent)
48+
XCTAssertTrue(splitClientConfig.encryptionEnabled)
49+
XCTAssertEqual(.verbose, splitClientConfig.logLevel)
50+
}
51+
52+
func testEnableDebugLogLevelIsMappedCorrectly() {
53+
let configValues: [String: Any] = ["enableDebug": true]
54+
let splitClientConfig = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
55+
XCTAssertEqual(SplitLogLevel.debug, splitClientConfig.logLevel)
56+
}
57+
58+
func testLogLevelsAreMappedCorrectly() {
59+
let logLevels = ["verbose", "debug", "info", "warning", "error", "none"]
60+
let expectedLogLevels: [SplitLogLevel] = [.verbose, .debug, .info, .warning, .error, .none]
61+
62+
for (index, logLevel) in logLevels.enumerated() {
63+
let configValues: [String: Any] = ["logLevel": logLevel]
64+
let config = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
65+
XCTAssertEqual(expectedLogLevels[index], config.logLevel)
66+
}
67+
}
68+
69+
func testUserConsentIsMappedCorrectly() {
70+
let userConsents = ["granted", "unknown", "declined", "any"]
71+
let expectedUserConsents: [UserConsent] = [.granted, .unknown, .declined, .granted]
72+
73+
for (index, userConsent) in userConsents.enumerated() {
74+
let configValues: [String: Any] = ["userConsent": userConsent]
75+
let config = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
76+
XCTAssertEqual(expectedUserConsents[index], config.userConsent)
77+
}
78+
}
79+
80+
func testImpressionsModeValuesAreMappedCorrectly() {
81+
let impressionsModes = ["debug", "none", "optimized"]
82+
let expectedImpressionsModes: [ImpressionsMode] = [.debug, .none, .optimized]
83+
84+
for (index, impressionsMode) in impressionsModes.enumerated() {
85+
let configValues: [String: Any] = ["impressionsMode": impressionsMode]
86+
let config = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
87+
XCTAssertEqual(expectedImpressionsModes[index].rawValue, config.impressionsMode)
88+
}
4089
}
4190
}

splitio_ios/example/ios/SplitTests/SplitTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,15 @@ class SplitFactoryStub: SplitFactory {
235235

236236
var apiKey: String
237237

238+
var userConsent: UserConsent
239+
238240
init(apiKey: String, client: SplitClient) {
239241
self.apiKey = apiKey
240242
self.client = client
241243
self.nilBucketingKeyClient = SplitClientStub()
242244
manager = SplitManagerStub()
243245
version = "0.0.0-stub"
246+
userConsent = .unknown
244247
}
245248

246249
convenience init(apiKey: String) {
@@ -267,6 +270,14 @@ class SplitFactoryStub: SplitFactory {
267270
func client(matchingKey: String, bucketingKey: String?) -> SplitClient {
268271
return client
269272
}
273+
274+
func setUserConsent(enabled: Bool) {
275+
if (enabled) {
276+
self.userConsent = .granted
277+
} else {
278+
self.userConsent = .declined
279+
}
280+
}
270281
}
271282

272283
class SplitClientStub: SplitClient {

splitio_ios/ios/Classes/SplitClientConfigHelper.swift

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ 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 IMPRESSIONS_MODE = "impressionsMode"
28+
static private let SYNC_ENABLED = "syncEnabled"
29+
static private let USER_CONSENT = "userConsent"
30+
static private let ENCRYPTION_ENABLED = "encryptionEnabled"
31+
static private let LOG_LEVEL = "logLevel"
2732

2833
static func fromMap(configurationMap: [String: Any?], impressionListener: SplitImpressionListener?) -> SplitClientConfig {
2934
let config = SplitClientConfig()
@@ -84,7 +89,11 @@ class SplitClientConfigHelper {
8489

8590
if configurationMap[ENABLE_DEBUG] != nil {
8691
if let enableDebug = configurationMap[ENABLE_DEBUG] as? Bool {
87-
config.isDebugModeEnabled = enableDebug
92+
if (enableDebug) {
93+
config.logLevel = .debug
94+
} else {
95+
config.logLevel = .none
96+
}
8897
}
8998
}
9099

@@ -150,6 +159,46 @@ class SplitClientConfigHelper {
150159
config.sync = syncConfigBuilder.build()
151160
}
152161
}
162+
163+
if let impressionsMode = configurationMap[IMPRESSIONS_MODE] as? String {
164+
config.impressionsMode = impressionsMode.uppercased()
165+
}
166+
167+
if let syncEnabled = configurationMap[SYNC_ENABLED] as? Bool {
168+
config.syncEnabled = syncEnabled
169+
}
170+
171+
if let userConsent = configurationMap[USER_CONSENT] as? String {
172+
switch userConsent.lowercased() {
173+
case "unknown":
174+
config.userConsent = .unknown
175+
case "declined":
176+
config.userConsent = .declined
177+
default:
178+
config.userConsent = .granted
179+
}
180+
}
181+
182+
if let encryptionEnabled = configurationMap[ENCRYPTION_ENABLED] as? Bool {
183+
config.encryptionEnabled = encryptionEnabled
184+
}
185+
186+
if let logLevel = configurationMap[LOG_LEVEL] as? String {
187+
switch logLevel.lowercased() {
188+
case "verbose":
189+
config.logLevel = .verbose
190+
case "debug":
191+
config.logLevel = .debug
192+
case "info":
193+
config.logLevel = .info
194+
case "warning":
195+
config.logLevel = .warning
196+
case "error":
197+
config.logLevel = .error
198+
default:
199+
config.logLevel = .none
200+
}
201+
}
153202

154203
config.serviceEndpoints = serviceEndpointsBuilder.build()
155204

splitio_ios/ios/splitio_ios.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
Pod::Spec.new do |s|
66
s.name = 'splitio_ios'
7-
s.version = '0.1.0'
7+
s.version = '0.2.0'
88
s.summary = 'split.io official Flutter plugin.'
99
s.description = <<-DESC
1010
split.io official Flutter plugin.
@@ -15,7 +15,7 @@ split.io official Flutter plugin.
1515
s.source = { :path => '.' }
1616
s.source_files = 'Classes/**/*'
1717
s.dependency 'Flutter'
18-
s.dependency 'Split', '~> 2.15.0'
18+
s.dependency 'Split', '~> 2.20.1'
1919
s.platform = :ios, '9.0'
2020

2121
# Flutter.framework does not contain a i386 slice.

0 commit comments

Comments
 (0)