Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions splitio_ios/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- Flutter (1.0.0)
- Split (2.15.0)
- splitio_ios (0.1.0):
- Split (2.20.1)
- splitio_ios (0.2.0):
- Flutter
- Split (~> 2.15.0)
- Split (~> 2.20.1)

DEPENDENCIES:
- Flutter (from `Flutter`)
Expand All @@ -21,8 +21,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
Split: d103c6afa47b5d1eac21e066c6bc09c879b21798
splitio_ios: 665651004a4984a415386b1eed4ae315b50bc069
Split: afbdfda76fe2c90bd449564eed2d83de00c0ff69
splitio_ios: e6d3dfe108ba894129a6b249d8914e3c44f0ffc4

PODFILE CHECKSUM: 6ab177d3659abbf5f15e864674366127c98cb8c0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
import XCTest
@testable import splitio_ios
@testable import Split

class SplitClientConfigHelperTests: XCTestCase {

func testConfigValuesAreMappedCorrectly() throws {
let configValues: [String: Any?] = ["featuresRefreshRate": 80000,
"segmentsRefreshRate": 70000,
"impressionsRefreshRate": 60000,
"telemetryRefreshRate": 2000,
"eventsQueueSize": 3999,
"impressionsQueueSize": 2999,
"eventFlushInterval": 40000,
"eventsPerPush": 5000,
"trafficType": "none",
"connectionTimeOut": 10,
"readTimeout": 25,
"disableLabels": true,
"enableDebug": true,
"proxyHost": "https://proxy",
"ready": 25,
"streamingEnabled": true,
"persistentAttributesEnabled": true,
"syncConfig": ["syncConfigNames": ["split1", "split2"], "syncConfigPrefixes": ["split_", "my_split_"]]]
"segmentsRefreshRate": 70000,
"impressionsRefreshRate": 60000,
"telemetryRefreshRate": 2000,
"eventsQueueSize": 3999,
"impressionsQueueSize": 2999,
"eventFlushInterval": 40000,
"eventsPerPush": 5000,
"trafficType": "none",
"connectionTimeOut": 10,
"readTimeout": 25,
"disableLabels": true,
"proxyHost": "https://proxy",
"ready": 25,
"streamingEnabled": true,
"persistentAttributesEnabled": true,
"syncConfig": ["syncConfigNames": ["split1", "split2"], "syncConfigPrefixes": ["split_", "my_split_"]],
"impressionsMode": "none",
"syncEnabled": false,
"userConsent": "declined",
"encryptionEnabled": true,
"logLevel": "verbose"
]

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

Expand All @@ -34,8 +40,51 @@ class SplitClientConfigHelperTests: XCTestCase {
XCTAssert(40000 == splitClientConfig.eventsPushRate)
XCTAssert(5000 == splitClientConfig.eventsPerPush)
XCTAssert("none" == splitClientConfig.trafficType)
XCTAssert(splitClientConfig.isDebugModeEnabled)
XCTAssert(splitClientConfig.streamingEnabled)
XCTAssert(splitClientConfig.persistentAttributesEnabled)
XCTAssertEqual("NONE", splitClientConfig.impressionsMode)
XCTAssertFalse(splitClientConfig.syncEnabled)
XCTAssertEqual(.declined, splitClientConfig.userConsent)
XCTAssertTrue(splitClientConfig.encryptionEnabled)
XCTAssertEqual(.verbose, splitClientConfig.logLevel)
}

func testEnableDebugLogLevelIsMappedCorrectly() {
let configValues: [String: Any] = ["enableDebug": true]
let splitClientConfig = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
XCTAssertEqual(SplitLogLevel.debug, splitClientConfig.logLevel)
}

func testLogLevelsAreMappedCorrectly() {
let logLevels = ["verbose", "debug", "info", "warning", "error", "none"]
let expectedLogLevels: [SplitLogLevel] = [.verbose, .debug, .info, .warning, .error, .none]

for (index, logLevel) in logLevels.enumerated() {
let configValues: [String: Any] = ["logLevel": logLevel]
let config = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
XCTAssertEqual(expectedLogLevels[index], config.logLevel)
}
}

func testUserConsentIsMappedCorrectly() {
let userConsents = ["granted", "unknown", "declined", "any"]
let expectedUserConsents: [UserConsent] = [.granted, .unknown, .declined, .granted]

for (index, userConsent) in userConsents.enumerated() {
let configValues: [String: Any] = ["userConsent": userConsent]
let config = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
XCTAssertEqual(expectedUserConsents[index], config.userConsent)
}
}

func testImpressionsModeValuesAreMappedCorrectly() {
let impressionsModes = ["debug", "none", "optimized"]
let expectedImpressionsModes: [ImpressionsMode] = [.debug, .none, .optimized]

for (index, impressionsMode) in impressionsModes.enumerated() {
let configValues: [String: Any] = ["impressionsMode": impressionsMode]
let config = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
XCTAssertEqual(expectedImpressionsModes[index].rawValue, config.impressionsMode)
}
}
}
11 changes: 11 additions & 0 deletions splitio_ios/example/ios/SplitTests/SplitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,15 @@ class SplitFactoryStub: SplitFactory {

var apiKey: String

var userConsent: UserConsent

init(apiKey: String, client: SplitClient) {
self.apiKey = apiKey
self.client = client
self.nilBucketingKeyClient = SplitClientStub()
manager = SplitManagerStub()
version = "0.0.0-stub"
userConsent = .unknown
}

convenience init(apiKey: String) {
Expand All @@ -267,6 +270,14 @@ class SplitFactoryStub: SplitFactory {
func client(matchingKey: String, bucketingKey: String?) -> SplitClient {
return client
}

func setUserConsent(enabled: Bool) {
if (enabled) {
self.userConsent = .granted
} else {
self.userConsent = .declined
}
}
}

class SplitClientStub: SplitClient {
Expand Down
51 changes: 50 additions & 1 deletion splitio_ios/ios/Classes/SplitClientConfigHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class SplitClientConfigHelper {
static private let SYNC_CONFIG = "syncConfig"
static private let SYNC_CONFIG_NAMES = "syncConfigNames"
static private let SYNC_CONFIG_PREFIXES = "syncConfigPrefixes"
static private let IMPRESSIONS_MODE = "impressionsMode"
static private let SYNC_ENABLED = "syncEnabled"
static private let USER_CONSENT = "userConsent"
static private let ENCRYPTION_ENABLED = "encryptionEnabled"
static private let LOG_LEVEL = "logLevel"

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

if configurationMap[ENABLE_DEBUG] != nil {
if let enableDebug = configurationMap[ENABLE_DEBUG] as? Bool {
config.isDebugModeEnabled = enableDebug
if (enableDebug) {
config.logLevel = .debug
} else {
config.logLevel = .none
}
}
}

Expand Down Expand Up @@ -150,6 +159,46 @@ class SplitClientConfigHelper {
config.sync = syncConfigBuilder.build()
}
}

if let impressionsMode = configurationMap[IMPRESSIONS_MODE] as? String {
config.impressionsMode = impressionsMode.uppercased()
}

if let syncEnabled = configurationMap[SYNC_ENABLED] as? Bool {
config.syncEnabled = syncEnabled
}

if let userConsent = configurationMap[USER_CONSENT] as? String {
switch userConsent.lowercased() {
case "unknown":
config.userConsent = .unknown
case "declined":
config.userConsent = .declined
default:
config.userConsent = .granted
}
}

if let encryptionEnabled = configurationMap[ENCRYPTION_ENABLED] as? Bool {
config.encryptionEnabled = encryptionEnabled
}

if let logLevel = configurationMap[LOG_LEVEL] as? String {
switch logLevel.lowercased() {
case "verbose":
config.logLevel = .verbose
case "debug":
config.logLevel = .debug
case "info":
config.logLevel = .info
case "warning":
config.logLevel = .warning
case "error":
config.logLevel = .error
default:
config.logLevel = .none
}
}

config.serviceEndpoints = serviceEndpointsBuilder.build()

Expand Down
4 changes: 2 additions & 2 deletions splitio_ios/ios/splitio_ios.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'splitio_ios'
s.version = '0.1.0'
s.version = '0.2.0'
s.summary = 'split.io official Flutter plugin.'
s.description = <<-DESC
split.io official Flutter plugin.
Expand All @@ -15,7 +15,7 @@ split.io official Flutter plugin.
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'Split', '~> 2.15.0'
s.dependency 'Split', '~> 2.20.1'
s.platform = :ios, '9.0'

# Flutter.framework does not contain a i386 slice.
Expand Down