From 740a1773cc492e4cae37c56eea68ddb30c953efb Mon Sep 17 00:00:00 2001 From: Zilin Zhang Date: Fri, 4 Jun 2021 11:23:52 -0700 Subject: [PATCH] Fix AEM issues Reviewed By: joesus, dreamolight Differential Revision: D28892952 fbshipit-source-id: 0734cc825a443f687bf1046c01eedd42f64b0763 (cherry picked from commit 59d13656842ddd31b4a3cccfa0468792e976cbd2) --- .../AEM/FBSDKAEMAdvertiserRuleFactory.m | 2 +- .../AEM/FBSDKAEMAdvertiserSingleEntryRule.m | 6 ++--- .../FBSDKAEMAdvertiserRuleFactoryTests.swift | 4 ++-- ...SDKAEMAdvertiserSingleEntryRuleTests.swift | 23 +++++++++++++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/AEM/FBSDKAEMAdvertiserRuleFactory.m b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/AEM/FBSDKAEMAdvertiserRuleFactory.m index 3c17377153..9f41eeed2d 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/AEM/FBSDKAEMAdvertiserRuleFactory.m +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/AEM/FBSDKAEMAdvertiserRuleFactory.m @@ -169,7 +169,7 @@ - (FBSDKAEMAdvertiserRuleOperator)getOperator:(NSDictionary *)ru @"is_any", @"is_not_any" ]; - NSInteger index = [operatorKeys indexOfObject:key]; + NSInteger index = [operatorKeys indexOfObject:key.lowercaseString]; return index == NSNotFound ? Unknown : index; } diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/AEM/FBSDKAEMAdvertiserSingleEntryRule.m b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/AEM/FBSDKAEMAdvertiserSingleEntryRule.m index 3e26905fba..152a1ddb89 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/AEM/FBSDKAEMAdvertiserSingleEntryRule.m +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/AEM/FBSDKAEMAdvertiserSingleEntryRule.m @@ -75,6 +75,9 @@ - (BOOL)isMatchedEventParameters:(nullable NSDictionary *)eventP return NO; } NSString *param = [FBSDKTypeUtility stringValueOrNil:paramPath.firstObject]; + if ([param hasSuffix:ASTERISK_DELIMETER]) { + return [self isMatchedWithAsteriskParam:param eventParameters:eventParams paramPath:paramPath]; + } // if data does not contain the key, we should return false directly. if (!param || ![[eventParams allKeys] containsObject:param]) { return NO; @@ -107,9 +110,6 @@ - (BOOL)isMatchedEventParameters:(nullable NSDictionary *)eventP } return [self isMatchedWithStringValue:stringValue numericalValue:numericalValue]; } - if ([param hasSuffix:ASTERISK_DELIMETER]) { - return [self isMatchedWithAsteriskParam:param eventParameters:eventParams paramPath:paramPath]; - } NSDictionary *subParams = [FBSDKTypeUtility dictionary:eventParams objectForKey:param ofType:NSDictionary.class]; NSRange range = NSMakeRange(1, paramPath.count - 1); NSArray *subParamPath = [paramPath subarrayWithRange:range]; diff --git a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AEM/FBSDKAEMAdvertiserRuleFactoryTests.swift b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AEM/FBSDKAEMAdvertiserRuleFactoryTests.swift index 79df709e07..0399ee11c7 100644 --- a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AEM/FBSDKAEMAdvertiserRuleFactoryTests.swift +++ b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AEM/FBSDKAEMAdvertiserRuleFactoryTests.swift @@ -173,8 +173,8 @@ class FBSDKAEMAdvertiserRuleFactoryTests: XCTestCase { // swiftlint:disable:this "Should get the expected Unknown operator of the dictionary") XCTAssertEqual( factory.getOperator(["And": "abc"]), - .Unknown, - "Should get the expected Unknown operator of the dictionary") + AEMAdvertiserRuleOperator.FBSDKAEMAdvertiserRuleOperatorAnd, + "Should get the expected AND operator of the dictionary") XCTAssertEqual( factory.getOperator(["and": "abc"]), AEMAdvertiserRuleOperator.FBSDKAEMAdvertiserRuleOperatorAnd, diff --git a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AEM/FBSDKAEMAdvertiserSingleEntryRuleTests.swift b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AEM/FBSDKAEMAdvertiserSingleEntryRuleTests.swift index e864d8149b..d8fc45f3b3 100644 --- a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AEM/FBSDKAEMAdvertiserSingleEntryRuleTests.swift +++ b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AEM/FBSDKAEMAdvertiserSingleEntryRuleTests.swift @@ -82,6 +82,29 @@ class FBSDKAEMAdvertiserSingleEntryRuleTests: XCTestCase { ) } + func testIsMatchedWithEventParametersForAsteriskOperator() { + let rule = AEMAdvertiserSingleEntryRule( + with: AEMAdvertiserRuleOperator.FBSDKAEMAdvertiserRuleOperatorContains, + paramKey: "fb_content[*].id", + linguisticCondition: "coffee", + numericalCondition: nil, + arrayCondition: nil + ) + + XCTAssertTrue( + rule.isMatchedEventParameters(["fb_content": [["id": "shop"], ["id": "coffeeshop"]]]), + "Should expect the event parameter matched with the rule" + ) + XCTAssertFalse( + rule.isMatchedEventParameters(["fb_content": ["id": "coffeeshop"]]), + "Should not expect the event parameter matched with the rule without expected item" + ) + XCTAssertFalse( + rule.isMatchedEventParameters(["fb_content": [["id": "shop"]]]), + "Should not expect the event parameter matched with the rule without expected id" + ) + } + func testIsMatchedWithEventParametersAndAsterisk() { let rule = AEMAdvertiserSingleEntryRule( with: AEMAdvertiserRuleOperator.FBSDKAEMAdvertiserRuleOperatorContains,