Skip to content

Commit

Permalink
Fix AEM issues
Browse files Browse the repository at this point in the history
Reviewed By: joesus, dreamolight

Differential Revision: D28892952

fbshipit-source-id: 0734cc825a443f687bf1046c01eedd42f64b0763
(cherry picked from commit 59d1365)
  • Loading branch information
KylinChang authored and jawwad committed Jun 4, 2021
1 parent 2612b0b commit 740a177
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ - (FBSDKAEMAdvertiserRuleOperator)getOperator:(NSDictionary<NSString *, id> *)ru
@"is_any",
@"is_not_any"
];
NSInteger index = [operatorKeys indexOfObject:key];
NSInteger index = [operatorKeys indexOfObject:key.lowercaseString];
return index == NSNotFound ? Unknown : index;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ - (BOOL)isMatchedEventParameters:(nullable NSDictionary<NSString *, id> *)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;
Expand Down Expand Up @@ -107,9 +110,6 @@ - (BOOL)isMatchedEventParameters:(nullable NSDictionary<NSString *, id> *)eventP
}
return [self isMatchedWithStringValue:stringValue numericalValue:numericalValue];
}
if ([param hasSuffix:ASTERISK_DELIMETER]) {
return [self isMatchedWithAsteriskParam:param eventParameters:eventParams paramPath:paramPath];
}
NSDictionary<NSString *, id> *subParams = [FBSDKTypeUtility dictionary:eventParams objectForKey:param ofType:NSDictionary.class];
NSRange range = NSMakeRange(1, paramPath.count - 1);
NSArray *subParamPath = [paramPath subarrayWithRange:range];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 740a177

Please sign in to comment.