Skip to content

Commit 79918e0

Browse files
committed
add normalizedHashedEmailUserIdentityType to class, fix tests
1 parent 1312964 commit 79918e0

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/roktManager.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default class RoktManager {
9999
private launcherOptions?: IRoktLauncherOptions;
100100
private logger: SDKLoggerApi;
101101
private domain?: string;
102-
private hashedEmailUserIdentityType?: string | null;
102+
private normalizedHashedEmailUserIdentityType?: string | null;
103103
/**
104104
* Initializes the RoktManager with configuration settings and user data.
105105
*
@@ -120,8 +120,8 @@ export default class RoktManager {
120120
options?: IRoktOptions
121121
): void {
122122
const { userAttributeFilters, settings } = roktConfig || {};
123-
const { placementAttributesMapping, configSettings } = settings || {};
124-
this.hashedEmailUserIdentityType = configSettings?.hashedEmailUserIdentityType;
123+
const { placementAttributesMapping, hashedEmailUserIdentityType } = settings || {};
124+
this.normalizedHashedEmailUserIdentityType = hashedEmailUserIdentityType?.toLowerCase() ?? null;
125125

126126
this.identityService = identityService;
127127
this.store = store;
@@ -184,21 +184,21 @@ export default class RoktManager {
184184
const sandboxValue = attributes?.sandbox || null;
185185
const mappedAttributes = this.mapPlacementAttributes(attributes, this.placementAttributesMapping);
186186

187-
const normalizedHashedEmailUserIdentityType = this.hashedEmailUserIdentityType?.toLowerCase() || null;
188-
189187
// Get current user identities
190188
this.currentUser = this.identityService.getCurrentUser();
191189
const currentUserIdentities = this.currentUser?.getUserIdentities()?.userIdentities || {};
192190

193191
const currentEmail = currentUserIdentities.email;
194192
const newEmail = mappedAttributes.email as string;
193+
const mappedEmailShaIdentityType = this.normalizedHashedEmailUserIdentityType;
195194

196195
let currentHashedEmail: string | undefined;
197196
let newHashedEmail: string | undefined;
198197

199198
// Hashed email identity is valid if it is set to Other-Other10
200-
if(normalizedHashedEmailUserIdentityType && IdentityType.getIdentityType(normalizedHashedEmailUserIdentityType) !== false) {
201-
currentHashedEmail = currentUserIdentities[normalizedHashedEmailUserIdentityType];
199+
200+
if(mappedEmailShaIdentityType && IdentityType.getIdentityType(mappedEmailShaIdentityType) !== false) {
201+
currentHashedEmail = currentUserIdentities[mappedEmailShaIdentityType];
202202
newHashedEmail = mappedAttributes['emailsha256'] as string || undefined;
203203
}
204204

@@ -214,8 +214,8 @@ export default class RoktManager {
214214
}
215215

216216
if (hashedEmailChanged) {
217-
newIdentities[normalizedHashedEmailUserIdentityType] = newHashedEmail;
218-
this.logger.warning(`emailsha256 mismatch detected. Current mParticle ${normalizedHashedEmailUserIdentityType} identity, ${currentHashedEmail}, differs from from 'emailsha256' passed to selectPlacements call, ${newHashedEmail}. Proceeding to call identify with ${normalizedHashedEmailUserIdentityType} set to ${newHashedEmail}. Please verify your implementation`);
217+
newIdentities[mappedEmailShaIdentityType] = newHashedEmail;
218+
this.logger.warning(`emailsha256 mismatch detected. Current mParticle ${mappedEmailShaIdentityType} identity, ${currentHashedEmail}, differs from 'emailsha256' passed to selectPlacements call, ${newHashedEmail}. Proceeding to call identify with ${mappedEmailShaIdentityType} set to ${newHashedEmail}. Please verify your implementation`);
219219
}
220220

221221
if (!isEmpty(newIdentities)) {

test/jest/roktManager.spec.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,17 @@ describe('RoktManager', () => {
364364
);
365365
expect(roktManager['domain']).toBe(domain);
366366
});
367+
368+
it('should set normalizedHashedEmailUserIdentityType as a lowercase hashedEmailUserIdentityType when passed as a setting', () => {
369+
roktManager.init(
370+
{settings: {hashedEmailUserIdentityType: 'Other5'}} as unknown as IKitConfigs,
371+
undefined,
372+
mockMPInstance.Identity,
373+
mockMPInstance._Store,
374+
mockMPInstance.Logger,
375+
);
376+
expect(roktManager['normalizedHashedEmailUserIdentityType']).toBe('other5');
377+
});
367378
});
368379

369380
describe('#attachKit', () => {
@@ -1043,7 +1054,7 @@ describe('RoktManager', () => {
10431054
};
10441055

10451056
roktManager.kit = kit as IRoktKit;
1046-
roktManager['hashedEmailUserIdentityType'] ='Other5';
1057+
roktManager['normalizedHashedEmailUserIdentityType'] ='other5';
10471058

10481059
// Set up fresh mocks for this test
10491060
const mockIdentity = {
@@ -1077,7 +1088,7 @@ describe('RoktManager', () => {
10771088
}
10781089
}, expect.any(Function));
10791090
expect(mockMPInstance.Logger.warning).toHaveBeenCalledWith(
1080-
"emailsha256 mismatch detected. Current mParticle other5 identity, old-other-value, differs from from 'emailsha256' passed to selectPlacements call, new-emailsha256-value. Proceeding to call identify with other5 set to new-emailsha256-value. Please verify your implementation"
1091+
"emailsha256 mismatch detected. Current mParticle other5 identity, old-other-value, differs from 'emailsha256' passed to selectPlacements call, new-emailsha256-value. Proceeding to call identify with other5 set to new-emailsha256-value. Please verify your implementation"
10811092
);
10821093
});
10831094

@@ -1097,7 +1108,7 @@ describe('RoktManager', () => {
10971108
};
10981109

10991110
roktManager.kit = kit as IRoktKit;
1100-
roktManager['hashedEmailUserIdentityType'] = 'Other5';
1111+
roktManager['normalizedHashedEmailUserIdentityType'] = 'other5';
11011112

11021113
// Set up fresh mocks for this test
11031114
const mockIdentity = {
@@ -1139,7 +1150,7 @@ describe('RoktManager', () => {
11391150
};
11401151

11411152
roktManager.kit = kit as IRoktKit;
1142-
roktManager['hashedEmailUserIdentityType'] = 'Other';
1153+
roktManager['normalizedHashedEmailUserIdentityType'] = 'other';
11431154

11441155
const mockIdentity = {
11451156
getCurrentUser: jest.fn().mockReturnValue({
@@ -1170,7 +1181,7 @@ describe('RoktManager', () => {
11701181
}
11711182
}, expect.any(Function));
11721183
expect(mockMPInstance.Logger.warning).toHaveBeenCalledWith(
1173-
"emailsha256 mismatch detected. Current mParticle other identity, undefined, differs from from 'emailsha256' passed to selectPlacements call, new-emailsha256-value. Proceeding to call identify with other set to new-emailsha256-value. Please verify your implementation"
1184+
"emailsha256 mismatch detected. Current mParticle other identity, undefined, differs from 'emailsha256' passed to selectPlacements call, new-emailsha256-value. Proceeding to call identify with other set to new-emailsha256-value. Please verify your implementation"
11741185
);
11751186
});
11761187

0 commit comments

Comments
 (0)