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
31 changes: 31 additions & 0 deletions UnitTests/MPRoktTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,37 @@ - (void)testTriggeredIdentifyWithMismatchedEmailIdentity {
[self.identityMock verifyWithDelay:0.2];
}

- (void)testTriggeredIdentifyWithMismatchedOtherIdentity {
MParticleUser *currentUser = [MParticle sharedInstance].identity.currentUser;

MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity];

NSArray *userIdentityArray = @[@{@"n" : [NSNumber numberWithLong:MPUserIdentityOther], @"i" : @"[email protected]"}];

[userDefaults setMPObject:userIdentityArray forKey:kMPUserIdentityArrayKey userId:currentUser.userId];
XCTAssertEqualObjects(currentUser.identities[@(MPIdentityOther)], @"[email protected]");

//Mock Identity as needed
MParticle *instance = [MParticle sharedInstance];
self.mockInstance = OCMPartialMock(instance);
self.identityMock = OCMClassMock([MPIdentityApi class]);
OCMStub([(MParticle *)self.mockInstance identity]).andReturn(self.identityMock);
[[[self.mockInstance stub] andReturn:self.mockInstance] sharedInstance];
[[[self.identityMock stub] andReturn:currentUser] currentUser];

[[self.identityMock expect] identify:[OCMArg checkWithBlock:^BOOL(MPIdentityApiRequest *request) {
XCTAssertEqualObjects([request.identities objectForKey:@(MPIdentityOther)], @"[email protected]");
return true;
}] completion:OCMOCK_ANY];

NSString *identifier = @"testView";
NSDictionary *attributes = @{@"emailsha256": @"[email protected]", @"sandbox": @"false"};

[self.rokt selectPlacements:identifier attributes:attributes];

[self.identityMock verifyWithDelay:0.2];
}

- (void)testPurchaseFinalized {
MParticle *instance = [MParticle sharedInstance];
self.mockInstance = OCMPartialMock(instance);
Expand Down
6 changes: 3 additions & 3 deletions mParticle-Apple-SDK/MPRokt.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ - (void)close {

- (void)confirmUser:(NSDictionary<NSString *, NSString *> * _Nullable)attributes user:(MParticleUser * _Nullable)user completion:(void (^)(MParticleUser *_Nullable))completion {
NSString *email = attributes[@"email"];
NSString *hashedEmail = attributes[@"other"];
NSString *hashedEmail = attributes[@"emailsha256"];

if ((email && ![email isEqualToString:user.identities[@(MPIdentityEmail)]]) || (hashedEmail && ![hashedEmail isEqualToString: user.identities[@(MPIdentityOther)]])) {
// If there is an existing email or hashed email but it doesn't match the what was passed in, warn the customer
if (user.identities[@(MPIdentityEmail)]) {
if (email && user.identities[@(MPIdentityEmail)]) {
NSLog(@"The existing email on the user (%@) does not match the email passed in to `selectPlacements:` (%@). Please remember to sync the email identity to mParticle as soon as you receive it. We will now identify the user before contuing to `selectPlacements:`", user.identities[@(MPIdentityEmail)], email);
} else if (user.identities[@(MPIdentityOther)]) {
} else if (hashedEmail && user.identities[@(MPIdentityOther)]) {
NSLog(@"The existing hashed email on the user (%@) does not match the email passed in to `selectPlacements:` (%@). Please remember to sync the email identity to mParticle as soon as you receive it. We will now identify the user before contuing to `selectPlacements:`", user.identities[@(MPIdentityOther)], hashedEmail);
}

Expand Down