Skip to content

Commit 475e5d4

Browse files
feat: Update Hashed Email for Rokt (#384)
1 parent 3b9e072 commit 475e5d4

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

UnitTests/MPRoktTests.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,37 @@ - (void)testTriggeredIdentifyWithMismatchedEmailIdentity {
397397
[self.identityMock verifyWithDelay:0.2];
398398
}
399399

400+
- (void)testTriggeredIdentifyWithMismatchedOtherIdentity {
401+
MParticleUser *currentUser = [MParticle sharedInstance].identity.currentUser;
402+
403+
MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity];
404+
405+
NSArray *userIdentityArray = @[@{@"n" : [NSNumber numberWithLong:MPUserIdentityOther], @"i" : @"[email protected]"}];
406+
407+
[userDefaults setMPObject:userIdentityArray forKey:kMPUserIdentityArrayKey userId:currentUser.userId];
408+
XCTAssertEqualObjects(currentUser.identities[@(MPIdentityOther)], @"[email protected]");
409+
410+
//Mock Identity as needed
411+
MParticle *instance = [MParticle sharedInstance];
412+
self.mockInstance = OCMPartialMock(instance);
413+
self.identityMock = OCMClassMock([MPIdentityApi class]);
414+
OCMStub([(MParticle *)self.mockInstance identity]).andReturn(self.identityMock);
415+
[[[self.mockInstance stub] andReturn:self.mockInstance] sharedInstance];
416+
[[[self.identityMock stub] andReturn:currentUser] currentUser];
417+
418+
[[self.identityMock expect] identify:[OCMArg checkWithBlock:^BOOL(MPIdentityApiRequest *request) {
419+
XCTAssertEqualObjects([request.identities objectForKey:@(MPIdentityOther)], @"[email protected]");
420+
return true;
421+
}] completion:OCMOCK_ANY];
422+
423+
NSString *identifier = @"testView";
424+
NSDictionary *attributes = @{@"emailsha256": @"[email protected]", @"sandbox": @"false"};
425+
426+
[self.rokt selectPlacements:identifier attributes:attributes];
427+
428+
[self.identityMock verifyWithDelay:0.2];
429+
}
430+
400431
- (void)testPurchaseFinalized {
401432
MParticle *instance = [MParticle sharedInstance];
402433
self.mockInstance = OCMPartialMock(instance);

mParticle-Apple-SDK/MPRokt.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ - (void)close {
199199

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

204204
if ((email && ![email isEqualToString:user.identities[@(MPIdentityEmail)]]) || (hashedEmail && ![hashedEmail isEqualToString: user.identities[@(MPIdentityOther)]])) {
205205
// If there is an existing email or hashed email but it doesn't match the what was passed in, warn the customer
206-
if (user.identities[@(MPIdentityEmail)]) {
206+
if (email && user.identities[@(MPIdentityEmail)]) {
207207
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);
208-
} else if (user.identities[@(MPIdentityOther)]) {
208+
} else if (hashedEmail && user.identities[@(MPIdentityOther)]) {
209209
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);
210210
}
211211

0 commit comments

Comments
 (0)