Skip to content

Commit

Permalink
fix: Mapped screen events forwarding to kits
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjenkins committed Sep 20, 2021
1 parent d7932da commit 86e7c75
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
98 changes: 98 additions & 0 deletions UnitTests/MPKitContainerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,104 @@ - (void)testMatchArrayProjection {
}
}

- (void)testScreenViewProjectionToBaseEvent {
[self setUserAttributesAndIdentities];

NSString *configurationStr = @"{ \
\"id\": 92, \
\"as\": { \
\"devKey\": \"INVALID_DEV_KEY\", \
\"appleAppId\": \"INVALID_APPLE_APP_ID\" \
}, \
\"hs\": {}, \
\"pr\": [ \
{ \
\"id\": 170, \
\"pmmid\": 29, \
\"behavior\": { \
\"append_unmapped_as_is\": true \
}, \
\"action\": { \
\"projected_event_name\": \"X_NEW_SUBSCRIPTION\", \
\"attribute_maps\": [], \
\"outbound_message_type\": 4 \
}, \
\"matches\": [ \
{ \
\"message_type\": 3, \
\"event_match_type\": \"String\", \
\"event\": \"SUBSCRIPTION_END\", \
\"attribute_key\": \"outcome\", \
\"attribute_values\": [ \
\"new_subscription\" \
] \
} \
] \
}, \
{ \
\"id\": 171, \
\"pmmid\": 30, \
\"behavior\": { \
\"append_unmapped_as_is\": true \
}, \
\"action\": { \
\"projected_event_name\": \"X_NEW_NOAH_SUBSCRIPTION\", \
\"attribute_maps\": [], \
\"outbound_message_type\": 4 \
}, \
\"matches\": [ \
{ \
\"message_type\": 4, \
\"event_match_type\": \"String\", \
\"event\": \"SUBSCRIPTION_END\", \
\"attribute_key\": \"Outcome\", \
\"attribute_values\": [ \
\"New_subscription\" \
] \
}, \
{ \
\"message_type\": 4, \
\"event_match_type\": \"String\", \
\"event\": \"SUBSCRIPTION_END\", \
\"attribute_key\": \"plan_id\", \
\"attribute_values\": [ \
\"3\", \
\"8\" \
] \
} \
] \
} \
] \
}";

NSData *configurationData = [configurationStr dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *configurationDictionary = [NSJSONSerialization JSONObjectWithData:configurationData options:0 error:nil];
NSArray *configurations = @[configurationDictionary];

[kitContainer configureKits:nil];
[kitContainer configureKits:configurations];

MPEvent *event = [[MPEvent alloc] initWithName:@"SUBSCRIPTION_END" type:MPEventTypeTransaction];
event.customAttributes = @{@"plan_id":@"3", @"outcome":@"new_subscription"};

MPKitRegister *kitRegister = [[MPKitRegister alloc] initWithName:@"AppsFlyer" className:@"MPKitAppsFlyerTest"];

id kitWrapperMock = OCMProtocolMock(@protocol(MPKitProtocol));
id kitRegisterMock = OCMPartialMock(kitRegister);
OCMStub([kitRegisterMock wrapperInstance]).andReturn(kitWrapperMock);

[(id <MPKitProtocol>)[kitWrapperMock expect] logBaseEvent:OCMOCK_ANY];
[(id <MPKitProtocol>)[kitWrapperMock reject] logScreen:OCMOCK_ANY];

MPKitFilter *kitFilter = [kitContainer filter:kitRegister forEvent:event selector:@selector(logScreen:)];

[kitWrapperMock verifyWithDelay:5.0];
[kitWrapperMock stopMocking];
[kitRegisterMock stopMocking];

XCTAssert([kitFilter.forwardEvent isKindOfClass:[MPEvent class]]);
}

- (void)testNonMatchingMatchArrayProjection {
[self setUserAttributesAndIdentities];

Expand Down
12 changes: 11 additions & 1 deletion mParticle-Apple-SDK/Kits/MPKitContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,17 @@ - (MPKitFilter *)filter:(id<MPExtensionKitProtocol>)kitRegister forEvent:(MPEven

for (auto &projectedEvent : projectedEvents) {
kitFilter = [[MPKitFilter alloc] initWithEvent:projectedEvent shouldFilter:shouldFilter appliedProjections:appliedProjectionsArray];
[self attemptToLogEventToKit:kitRegister kitFilter:kitFilter selector:selector parameters:nil messageType:messageTypeCode userInfo:[[NSDictionary alloc] init]];
SEL mutableSelector = selector;
if (selector == @selector(logScreen:)) {
for (int i = 0; i < appliedProjectionsArray.count; i += 1) {
auto appliedProjection = appliedProjectionsArray[i];
if (appliedProjection.outboundMessageType == MPMessageTypeEvent) {
mutableSelector = @selector(logBaseEvent:);
break;
}
}
}
[self attemptToLogEventToKit:kitRegister kitFilter:kitFilter selector:mutableSelector parameters:nil messageType:messageTypeCode userInfo:[[NSDictionary alloc] init]];
}
}];

Expand Down

0 comments on commit 86e7c75

Please sign in to comment.