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
14 changes: 11 additions & 3 deletions swift-sdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
00B6FACE210E88ED007535CF /* prod-1.mobileprovision in Resources */ = {isa = PBXBuildFile; fileRef = 00B6FACD210E874D007535CF /* prod-1.mobileprovision */; };
00B6FAD1210E8D90007535CF /* dev-1.mobileprovision in Resources */ = {isa = PBXBuildFile; fileRef = 00B6FAD0210E8D90007535CF /* dev-1.mobileprovision */; };
00CB31B621096129004ACDEC /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00CB31B4210960C4004ACDEC /* TestUtils.swift */; };
181063DF2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */; };
181063DB2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181063DA2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift */; };
181063DD2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181063DC2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift */; };
181063DF2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */; };
182A2A152C661C9A002FF058 /* DataTypeComparatorSearchQueryCriteria.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182A2A142C661C9A002FF058 /* DataTypeComparatorSearchQueryCriteria.swift */; };
1881A21B2C7602F80020C64D /* ComparatorDataTypeWithArrayInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1881A21A2C7602F80020C64D /* ComparatorDataTypeWithArrayInput.swift */; };
18A3520A2C7DC51C007FED53 /* NestedFieldSupportForArrayData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18A352092C7DC51C007FED53 /* NestedFieldSupportForArrayData.swift */; };
Expand Down Expand Up @@ -565,7 +567,9 @@
00B6FACD210E874D007535CF /* prod-1.mobileprovision */ = {isa = PBXFileReference; lastKnownFileType = file; path = "prod-1.mobileprovision"; sourceTree = "<group>"; };
00B6FAD0210E8D90007535CF /* dev-1.mobileprovision */ = {isa = PBXFileReference; lastKnownFileType = file; path = "dev-1.mobileprovision"; sourceTree = "<group>"; };
00CB31B4210960C4004ACDEC /* TestUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestUtils.swift; sourceTree = "<group>"; };
181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidateStoredEventCheckUnknownToKnownUserTest.swift; sourceTree = "<group>"; };
181063DA2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomEventUserUpdateTestCaseTests.swift; sourceTree = "<group>"; };
181063DC2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidateCustomEventUserUpdateAPITest.swift; sourceTree = "<group>"; };
181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidateStoredEventCheckUnknownToKnownUserTest.swift; sourceTree = "<group>"; };
182A2A142C661C9A002FF058 /* DataTypeComparatorSearchQueryCriteria.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataTypeComparatorSearchQueryCriteria.swift; sourceTree = "<group>"; };
1881A21A2C7602F80020C64D /* ComparatorDataTypeWithArrayInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComparatorDataTypeWithArrayInput.swift; sourceTree = "<group>"; };
18A352092C7DC51C007FED53 /* NestedFieldSupportForArrayData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NestedFieldSupportForArrayData.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1688,7 +1692,9 @@
18E23ADF2C6CDE97002B2D92 /* CombinationLogicEventTypeCriteria.swift */,
18A352092C7DC51C007FED53 /* NestedFieldSupportForArrayData.swift */,
18A3520B2C85BAF0007FED53 /* IsOneOfInNotOneOfCriteareaTest.swift */,
181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */,
181063DA2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift */,
181063DC2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift */,
181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */,
);
name = "anonymous-tracking-tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -2326,6 +2332,7 @@
55AEA95925F05B7D00B38CED /* InAppMessageProcessorTests.swift in Sources */,
ACC362B824D17005002C67BA /* IterableRequestTests.swift in Sources */,
AC2C668720D3435700D46CC9 /* ActionRunnerTests.swift in Sources */,
181063DB2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift in Sources */,
00CB31B621096129004ACDEC /* TestUtils.swift in Sources */,
AC89661E2124FBCE0051A6CD /* AutoRegistrationTests.swift in Sources */,
9FF05EAF2AFEA5FA005311F7 /* MockAuthManager.swift in Sources */,
Expand Down Expand Up @@ -2391,6 +2398,7 @@
55B5498423973B5C00243E87 /* InboxSessionManagerTests.swift in Sources */,
ACB37AB0240268A60093A8EA /* SampleInboxViewDelegateImplementations.swift in Sources */,
5588DF7928C04463000697D7 /* MockNotificationResponse.swift in Sources */,
181063DD2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift in Sources */,
AC3A2FF0262EDD4C00425435 /* InAppPriorityTests.swift in Sources */,
ACD6116E21080564003E7F6B /* IterableAPITests.swift in Sources */,
5588DF8928C044BE000697D7 /* MockCustomActionDelegate.swift in Sources */,
Expand Down
28 changes: 19 additions & 9 deletions swift-sdk/Internal/AnonymousUserManager+Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,7 @@ struct CriteriaCompletionChecker {
if let valueFromObj = getFieldValue(data: eventData, field: field), let comparatorType = query[JsonKey.CriteriaItem.comparatorType] as? String {
return evaluateComparison(comparatorType: comparatorType, matchObj: valueFromObj, valueToCompare: query[JsonKey.CriteriaItem.value] ?? query[JsonKey.CriteriaItem.values])
}
}


if doesKeyExist {
} else if doesKeyExist {
if let comparatorType = query[JsonKey.CriteriaItem.comparatorType] as? String, (evaluateComparison(comparatorType: comparatorType, matchObj: eventData[field] ?? "", valueToCompare: query[JsonKey.CriteriaItem.value] ?? query[JsonKey.CriteriaItem.values])) {
return true
}
Expand All @@ -402,14 +399,27 @@ struct CriteriaCompletionChecker {
return matchResult
}


func getFieldValue(data: Any, field: String) -> Any? {
let fields = field.split(separator: ".").map { String($0) }
return fields.reduce(data) { (value, currentField) -> Any? in
if let dictionary = value as? [String: Any], let fieldValue = dictionary[currentField] {
return fieldValue
var fields = field.split(separator: ".").map(String.init)
if let dictionary = data as? [String: Any] ,let dataType = dictionary[JsonKey.eventType] as? String, dataType == EventType.customEvent, let firstField = fields.first, let eventName = dictionary[JsonKey.eventName] as? String, firstField == eventName {
fields.removeFirst()
}
var currentValue: Any? = data
for (index, currentField) in fields.enumerated() {
if index == fields.count - 1 {
if let currentDict = currentValue as? [String: Any] {
return currentDict[currentField]
}
} else {
if let currentDict = currentValue as? [String: Any], let nextValue = currentDict[currentField] {
currentValue = nextValue
} else {
return nil
}
}
return nil
}
return nil
}


Expand Down
14 changes: 7 additions & 7 deletions tests/unit-tests/AnonymousUserComplexCriteriaMatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
"comparatorType": "Equals",
"dataType": "customEvent",
"id": 23,
"value": "button.clicked"
"value": "button-clicked"
},
{
"field": "button-clicked.animal",
Expand Down Expand Up @@ -483,7 +483,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {

func testCompareDataWithCriteria1Success() {
let eventItems: [[AnyHashable: Any]] = [
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button.clicked", "dataFields": ["button-clicked.animal": "giraffe"]
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["animal": "giraffe"]
], [
"items": [["id": "12", "name": "keyboard", "price": 130, "quantity": 110]],
"createdAt": 1699246745093,
Expand All @@ -496,7 +496,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {

func testCompareDataWithCriteria1Failure() {
let eventItems: [[AnyHashable: Any]] = [
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button.clicked", "dataFields": ["button-clicked.animal": "giraffe22"]
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["animal": "giraffe22"]
], [
"items": [["id": "12", "name": "keyboard", "price": 130, "quantity": 110]],
"createdAt": 1699246745093,
Expand All @@ -508,7 +508,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {

func testCompareDataWithCriteria2Success() {
let eventItems: [[AnyHashable: Any]] = [
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["button-clicked.lastPageViewed": "welcome page"]
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["lastPageViewed": "welcome page"]
], ["dataType": "user", "createdAt": 1699246745093, "phone_number": "999999", "country": "USA", "dataFields": ["preferred_car_models": "Subaru"]
]]
let expectedCriteriaId = "51"
Expand All @@ -518,7 +518,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {

func testCompareDataWithCriteria2Failure() {
let eventItems: [[AnyHashable: Any]] = [
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["button-clicked.lastPageViewed": "welcome page"]
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["lastPageViewed": "welcome page"]
], ["dataType": "user", "createdAt": 1699246745093, "phone_number": "999999", "country": "USA", "dataFields": ["preferred_car_models": "Mazda"]
]]
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataForCriteria2)!, anonymousEvents: eventItems).getMatchedCriteria()
Expand All @@ -543,7 +543,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
], [
"dataType": "user", "createdAt": 1699246745093, "dataFields": [ "phone_number": "999999", "country": "USA", "preferred_car_models": "Subaru"]
], [
"dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["button-clicked.lastPageViewed": "welcome page"]
"dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["lastPageViewed": "welcome page"]
], ]

let expectedCriteriaId = "50"
Expand All @@ -555,7 +555,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
func testCompareDataWithCriteria3Failure() {
let eventItems: [[AnyHashable: Any]] = [
[
"dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked2", "dataFields": ["button-clicked.lastPageViewed": "welcome page"]
"dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked2", "dataFields": ["lastPageViewed": "welcome page"]
], [
"items": [["id": "12", "name": "keyboard", "price": 90, "quantity": 60]],
"createdAt": 1699246745093,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit-tests/AnonymousUserCriteriaIsSetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ class AnonymousUserCriteriaIsSetTests: XCTestCase {


func testCompareDataIsSetCustomEventSuccess() {
let eventItems: [[AnyHashable: Any]] = [["dataType": "customEvent", "eventName":"button-clicked", "dataFields": ["button-clicked":"cc", "button-clicked.animal": "aa", "button-clicked.clickCount": "1", "total": "10"]]]
let eventItems: [[AnyHashable: Any]] = [["dataType": "customEvent", "eventName":"button-clicked", "dataFields": ["button-clicked":"cc", "animal": "aa", "clickCount": "1", "total": "10"]]]
let expectedCriteriaId = "1"
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataCustomEvent)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, expectedCriteriaId)
}

func testCompareDataIsSetCustomEventFailure() {
let eventItems: [[AnyHashable: Any]] = [["dataType": "customEvent", "eventName":"vvv", "dataFields": ["button-clicked":"", "button-clicked.animal": "", "button-clicked.clickCount": "1", "total": "10"]]]
let eventItems: [[AnyHashable: Any]] = [["dataType": "customEvent", "eventName":"vvv", "dataFields": ["button-clicked":"", "animal": "", "clickCount": "1", "total": "10"]]]
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataCustomEvent)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, nil)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit-tests/AnonymousUserCriteriaMatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class AnonymousUserCriteriaMatchTests: XCTestCase {

func testCompareDataWithCustomEventCriteriaSuccess() {
let eventItems: [[AnyHashable: Any]] = [
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["button-clicked.lastPageViewed": "signup page"]
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["lastPageViewed": "signup page"]
]]
let expectedCriteriaId = "48"
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockData)!, anonymousEvents: eventItems).getMatchedCriteria()
Expand All @@ -259,7 +259,7 @@ class AnonymousUserCriteriaMatchTests: XCTestCase {

func testCompareDataWithCustomEventCriteriaFailure() {
let eventItems: [[AnyHashable: Any]] = [
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button", "dataFields": ["button-clicked.lastPageViewed": "signup page"]
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button", "dataFields": ["lastPageViewed": "signup page"]
]]
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockData)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, nil)
Expand Down
7 changes: 5 additions & 2 deletions tests/unit-tests/ComparatorDataTypeWithArrayInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ final class ComparatorDataTypeWithArrayInput: XCTestCase {
],
[
"dataType": "customEvent",
"button-clicked.animal": ["zirraf", "horse"]
"eventName": "button-clicked",
"dataFields": ["animal": ["zirraf", "horse"]]
],
[
"dataType": "purchase",
Expand All @@ -696,7 +697,9 @@ final class ComparatorDataTypeWithArrayInput: XCTestCase {
],
[
"dataType": "customEvent",
"button-clicked.animal": ["zirraf", "horse", "giraffe"]
"eventName": "button-clicked",
"dataFields": ["animal": ["zirraf", "horse", "giraffe"]]

],
[
"dataType": "purchase",
Expand Down
Loading