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
61 changes: 57 additions & 4 deletions splitio_ios/example/ios/SplitTests/SplitMethodParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,59 @@ class SplitMethodParserTests: XCTestCase {
}
}

func testGetTreatmentsByFlagSet() {
methodParser?.onMethodCall(methodName: "getTreatmentsByFlagSet", arguments: ["matchingKey": "user-key", "bucketingKey": "bucketing-key", "flagSet": "set_1", "attributes": ["age": 50]], result: { (_: Any?) in
return
})

if let splitWrapper = (splitWrapper as? SplitWrapperStub) {
XCTAssert(splitWrapper.matchingKeyValue == "user-key")
XCTAssert(splitWrapper.bucketingKeyValue == "bucketing-key")
XCTAssert(splitWrapper.flagSetValue == "set_1")
print(splitWrapper.attributesValue)
XCTAssert(NSDictionary(dictionary: ["age": 50]).isEqual(to: splitWrapper.attributesValue!))
}
}

func testGetTreatmentsByFlagSets() {
methodParser?.onMethodCall(methodName: "getTreatmentsByFlagSets", arguments: ["matchingKey": "user-key", "bucketingKey": "bucketing-key", "flagSets": ["set_1", "set_2"], "attributes": ["age": 50]], result: { (_: Any?) in
return
})

if let splitWrapper = (splitWrapper as? SplitWrapperStub) {
XCTAssert(splitWrapper.matchingKeyValue == "user-key")
XCTAssert(splitWrapper.bucketingKeyValue == "bucketing-key")
XCTAssert(splitWrapper.flagSetsValue == ["set_1", "set_2"])
XCTAssert(NSDictionary(dictionary: ["age": 50]).isEqual(to: splitWrapper.attributesValue!))
}
}

func testGetTreatmentsWithConfigByFlagSet() {
methodParser?.onMethodCall(methodName: "getTreatmentsWithConfigByFlagSet", arguments: ["matchingKey": "user-key", "bucketingKey": "bucketing-key", "flagSet": "set_1", "attributes": ["age": 50]], result: { (_: Any?) in
return
})

if let splitWrapper = (splitWrapper as? SplitWrapperStub) {
XCTAssert(splitWrapper.matchingKeyValue == "user-key")
XCTAssert(splitWrapper.bucketingKeyValue == "bucketing-key")
XCTAssert(splitWrapper.flagSetValue == "set_1")
XCTAssert(NSDictionary(dictionary: ["age": 50]).isEqual(to: splitWrapper.attributesValue!))
}
}

func testGetTreatmentsWithConfigByFlagSets() {
methodParser?.onMethodCall(methodName: "getTreatmentsWithConfigByFlagSets", arguments: ["matchingKey": "user-key", "bucketingKey": "bucketing-key", "flagSets": ["set_1", "set_2"], "attributes": ["age": 50]], result: { (_: Any?) in
return
})

if let splitWrapper = (splitWrapper as? SplitWrapperStub) {
XCTAssert(splitWrapper.matchingKeyValue == "user-key")
XCTAssert(splitWrapper.bucketingKeyValue == "bucketing-key")
XCTAssert(splitWrapper.flagSetsValue == ["set_1", "set_2"])
XCTAssert(NSDictionary(dictionary: ["age": 50]).isEqual(to: splitWrapper.attributesValue!))
}
}

func testTrackWithValue() {
methodParser?.onMethodCall(methodName: "track", arguments: ["matchingKey": "user-key", "bucketingKey": "bucketing-key", "eventType": "my_event", "value": 25.20], result: { (_: Any?) in
return
Expand Down Expand Up @@ -395,7 +448,7 @@ class SplitWrapperStub: SplitWrapper {
matchingKeyValue = matchingKey
bucketingKeyValue = bucketingKey
flagSetValue = flagSet
attributeValue = attributes
attributesValue = attributes

return [:]
}
Expand All @@ -404,7 +457,7 @@ class SplitWrapperStub: SplitWrapper {
matchingKeyValue = matchingKey
bucketingKeyValue = bucketingKey
flagSetsValue = flagSets
attributeValue = attributes
attributesValue = attributes

return [:]
}
Expand All @@ -413,7 +466,7 @@ class SplitWrapperStub: SplitWrapper {
matchingKeyValue = matchingKey
bucketingKeyValue = bucketingKey
flagSetValue = flagSet
attributeValue = attributes
attributesValue = attributes

return [:]
}
Expand All @@ -422,7 +475,7 @@ class SplitWrapperStub: SplitWrapper {
matchingKeyValue = matchingKey
bucketingKeyValue = bucketingKey
flagSetsValue = flagSets
attributeValue = attributes
attributesValue = attributes

return [:]
}
Expand Down
6 changes: 6 additions & 0 deletions splitio_ios/ios/Classes/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ enum Method: String {
case getTreatments = "getTreatments"
case getTreatmentWithConfig = "getTreatmentWithConfig"
case getTreatmentsWithConfig = "getTreatmentsWithConfig"
case getTreatmentsByFlagSet = "getTreatmentsByFlagSet"
case getTreatmentsByFlagSets = "getTreatmentsByFlagSets"
case getTreatmentsWithConfigByFlagSet = "getTreatmentsWithConfigByFlagSet"
case getTreatmentsWithConfigByFlagSets = "getTreatmentsWithConfigByFlagSets"
case track = "track"
case getAttribute = "getAttribute"
case getAllAttributes = "getAllAttributes"
Expand Down Expand Up @@ -40,4 +44,6 @@ enum Argument: String {
case value = "value"
case properties = "properties"
case attributeName = "attributeName"
case flagSet = "flagSet"
case flagSets = "flagSets"
}
5 changes: 4 additions & 1 deletion splitio_ios/ios/Classes/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ extension SplitView {
"killed": splitView.killed,
"treatments": splitView.treatments,
"changeNumber": splitView.changeNumber,
"configs": splitView.configs]
"configs": splitView.configs,
"defaultTreatment": splitView.defaultTreatment,
"sets": splitView.sets
]
} else {
return [:]
}
Expand Down
86 changes: 72 additions & 14 deletions splitio_ios/ios/Classes/SplitMethodParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ class DefaultSplitMethodParser: SplitMethodParser {
splits: argumentParser.getStringListArgument(argumentName: .splitName, arguments: arguments),
attributes: argumentParser.getMapArgument(argumentName: .attributes, arguments: arguments) as [String: Any]))
break
case .getTreatmentsByFlagSet:
result(getTreatmentsByFlagSet(
matchingKey: argumentParser.getStringArgument(argumentName: .matchingKey, arguments: arguments) ?? "",
bucketingKey: argumentParser.getStringArgument(argumentName: .bucketingKey, arguments: arguments),
flagSet: argumentParser.getStringArgument(argumentName: .flagSet, arguments: arguments) ?? "",
attributes: argumentParser.getMapArgument(argumentName: .attributes, arguments: arguments) as [String: Any]))
break
case .getTreatmentsByFlagSets:
result(getTreatmentsByFlagSets(
matchingKey: argumentParser.getStringArgument(argumentName: .matchingKey, arguments: arguments) ?? "",
bucketingKey: argumentParser.getStringArgument(argumentName: .bucketingKey, arguments: arguments),
flagSets: argumentParser.getStringListArgument(argumentName: .flagSets, arguments: arguments),
attributes: argumentParser.getMapArgument(argumentName: .attributes, arguments: arguments) as [String: Any]))
break
case .getTreatmentsWithConfigByFlagSet:
result(getTreatmentsWithConfigByFlagSet(
matchingKey: argumentParser.getStringArgument(argumentName: .matchingKey, arguments: arguments) ?? "",
bucketingKey: argumentParser.getStringArgument(argumentName: .bucketingKey, arguments: arguments),
flagSet: argumentParser.getStringArgument(argumentName: .flagSet, arguments: arguments) ?? "",
attributes: argumentParser.getMapArgument(argumentName: .attributes, arguments: arguments) as [String: Any]))
break
case .getTreatmentsWithConfigByFlagSets:
result(getTreatmentsWithConfigByFlagSets(
matchingKey: argumentParser.getStringArgument(argumentName: .matchingKey, arguments: arguments) ?? "",
bucketingKey: argumentParser.getStringArgument(argumentName: .bucketingKey, arguments: arguments),
flagSets: argumentParser.getStringListArgument(argumentName: .flagSets, arguments: arguments),
attributes: argumentParser.getMapArgument(argumentName: .attributes, arguments: arguments) as [String: Any]))
break
case .track:
result(track(matchingKey: argumentParser.getStringArgument(argumentName: .matchingKey, arguments: arguments) ?? "",
bucketingKey: argumentParser.getStringArgument(argumentName: .bucketingKey, arguments: arguments),
Expand Down Expand Up @@ -215,6 +243,50 @@ class DefaultSplitMethodParser: SplitMethodParser {
}
}

private func getTreatmentsByFlagSet(matchingKey: String, bucketingKey: String? = nil, flagSet: String, attributes: [String: Any]? = [:]) -> [String: String] {
guard let splitWrapper = getSplitWrapper() else {
return [:]
}

let treatments = splitWrapper.getTreatmentsByFlagSet(matchingKey: matchingKey, flagSet: flagSet, bucketingKey: bucketingKey, attributes: attributes)

return treatments
}

private func getTreatmentsByFlagSets(matchingKey: String, bucketingKey: String? = nil, flagSets: [String], attributes: [String: Any]? = [:]) -> [String: String] {
guard let splitWrapper = getSplitWrapper() else {
return [:]
}

let treatments = splitWrapper.getTreatmentsByFlagSets(matchingKey: matchingKey, flagSets: flagSets, bucketingKey: bucketingKey, attributes: attributes)

return treatments
}

private func getTreatmentsWithConfigByFlagSet(matchingKey: String, bucketingKey: String? = nil, flagSet: String, attributes: [String: Any]? = [:]) -> [String: [String: String?]] {
guard let splitWrapper = getSplitWrapper() else {
return [:]
}

let treatments = splitWrapper.getTreatmentsWithConfigByFlagSet(matchingKey: matchingKey, flagSet: flagSet, bucketingKey: bucketingKey, attributes: attributes)

return treatments.mapValues {
["treatment": $0.treatment, "config": $0.config]
}
}

private func getTreatmentsWithConfigByFlagSets(matchingKey: String, bucketingKey: String? = nil, flagSets: [String], attributes: [String: Any]? = [:]) -> [String: [String: String?]] {
guard let splitWrapper = getSplitWrapper() else {
return [:]
}

let treatments = splitWrapper.getTreatmentsWithConfigByFlagSets(matchingKey: matchingKey, flagSets: flagSets, bucketingKey: bucketingKey, attributes: attributes)

return treatments.mapValues {
["treatment": $0.treatment, "config": $0.config]
}
}

private func track(matchingKey: String, bucketingKey: String? = nil, eventType: String, trafficType: String? = nil, value: Double? = nil, properties: [String: Any?]) -> Bool {
guard let splitWrapper = getSplitWrapper() else {
return false
Expand Down Expand Up @@ -320,18 +392,4 @@ class DefaultSplitMethodParser: SplitMethodParser {

return splitWrapper
}

private func getSplitViewAsMap(splitView: SplitView?) -> [String: Any?] {
if let splitView = splitView {
return [
"name": splitView.name,
"trafficType": splitView.trafficType,
"killed": splitView.killed,
"treatments": splitView.treatments,
"changeNumber": splitView.changeNumber,
"configs": splitView.configs]
} else {
return [:]
}
}
}
11 changes: 10 additions & 1 deletion splitio_platform_interface/lib/split_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class SplitView {
mappedConfig.addAll({entry.key.toString(): entry.value.toString()})
});

if (entry['treatments'] == null) {
entry['treatments'] = entry['treatments'] ?? [];
}

if (entry['sets'] == null) {
entry['sets'] = [];
}

return SplitView(
entry['name'],
entry['trafficType'],
Expand All @@ -32,7 +40,8 @@ class SplitView {
entry['changeNumber'],
mappedConfig,
entry['defaultTreatment'] ?? '',
(entry['sets'] ?? [] as List).map((el) => el as String).toList());
(entry['sets'] as List).map((el) => el as String).toList()
);
}

@override
Expand Down