Skip to content

Commit a729496

Browse files
committed
turn comments
1 parent bf68a45 commit a729496

2 files changed

Lines changed: 94 additions & 3 deletions

File tree

src/roktManager.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ export default class RoktManager {
191191
newHashedEmail = mappedAttributes['emailsha256'] as string || undefined;
192192
}
193193

194-
const emailChanged = !!(newEmail && (!currentEmail || currentEmail !== newEmail));
195-
const hashedEmailChanged = !!(newHashedEmail && (!currentHashedEmail || currentHashedEmail !== newHashedEmail));
196-
// https://go.mparticle.com/work/SQDSDKS-7338
194+
const emailChanged = this.hasIdentityChanged(currentEmail, newEmail);
195+
const hashedEmailChanged = this.hasIdentityChanged(currentHashedEmail, newHashedEmail);
196+
197197
const newIdentities: UserIdentities = {};
198198
if (emailChanged) {
199199
newIdentities.email = newEmail;
@@ -206,6 +206,7 @@ export default class RoktManager {
206206
newIdentities[normalizedHashedEmailUserIdentityType] = newHashedEmail;
207207
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`);
208208
}
209+
209210
if (!isEmpty(newIdentities)) {
210211
// Call identify with the new user identities
211212
try {
@@ -327,4 +328,27 @@ export default class RoktManager {
327328
private queueMessage(message: IRoktMessage): void {
328329
this.messageQueue.push(message);
329330
}
331+
332+
/**
333+
* Checks if an identity value has changed by comparing current and new values
334+
*
335+
* @param {string | undefined} currentValue - The current identity value
336+
* @param {string | undefined} newValue - The new identity value to compare against
337+
* @returns {boolean} True if the identity has changed (new value exists and differs from current), false otherwise
338+
*/
339+
private hasIdentityChanged(currentValue: string | undefined, newValue: string | undefined): boolean {
340+
if (!newValue) {
341+
return false;
342+
}
343+
344+
if (!currentValue) {
345+
return true; // New value exists but no current value
346+
}
347+
348+
if (currentValue !== newValue) {
349+
return true; // Values are different
350+
}
351+
352+
return false; // Values are the same
353+
}
330354
}

test/jest/roktManager.spec.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,4 +1266,71 @@ describe('RoktManager', () => {
12661266
}).toThrow('Error setting extension data: ' + mockError.message);
12671267
});
12681268
});
1269+
1270+
describe('#hasIdentityChanged', () => {
1271+
it('should return false when newValue is null', () => {
1272+
const result = roktManager['hasIdentityChanged']('current@example.com', null);
1273+
expect(result).toBe(false);
1274+
});
1275+
1276+
it('should return false when newValue is undefined', () => {
1277+
const result = roktManager['hasIdentityChanged']('current@example.com', undefined);
1278+
expect(result).toBe(false);
1279+
});
1280+
1281+
it('should return false when newValue is empty string', () => {
1282+
const result = roktManager['hasIdentityChanged']('current@example.com', '');
1283+
expect(result).toBe(false);
1284+
});
1285+
1286+
it('should return true when currentValue is null and newValue exists', () => {
1287+
const result = roktManager['hasIdentityChanged'](null, 'new@example.com');
1288+
expect(result).toBe(true);
1289+
});
1290+
1291+
it('should return true when currentValue is undefined and newValue exists', () => {
1292+
const result = roktManager['hasIdentityChanged'](undefined, 'new@example.com');
1293+
expect(result).toBe(true);
1294+
});
1295+
1296+
it('should return true when currentValue is empty string and newValue exists', () => {
1297+
const result = roktManager['hasIdentityChanged']('', 'new@example.com');
1298+
expect(result).toBe(true);
1299+
});
1300+
1301+
it('should return true when currentValue and newValue are different', () => {
1302+
const result = roktManager['hasIdentityChanged']('old@example.com', 'new@example.com');
1303+
expect(result).toBe(true);
1304+
});
1305+
1306+
it('should return false when currentValue and newValue are the same', () => {
1307+
const result = roktManager['hasIdentityChanged']('same@example.com', 'same@example.com');
1308+
expect(result).toBe(false);
1309+
});
1310+
1311+
it('should return false when both currentValue and newValue are null', () => {
1312+
const result = roktManager['hasIdentityChanged'](null, null);
1313+
expect(result).toBe(false);
1314+
});
1315+
1316+
it('should return false when both currentValue and newValue are undefined', () => {
1317+
const result = roktManager['hasIdentityChanged'](undefined, undefined);
1318+
expect(result).toBe(false);
1319+
});
1320+
1321+
it('should return false when both currentValue and newValue are empty strings', () => {
1322+
const result = roktManager['hasIdentityChanged']('', '');
1323+
expect(result).toBe(false);
1324+
});
1325+
1326+
it('should handle whitespace-only strings as valid values', () => {
1327+
const result = roktManager['hasIdentityChanged']('old@example.com', ' ');
1328+
expect(result).toBe(true);
1329+
});
1330+
1331+
it('should be case sensitive', () => {
1332+
const result = roktManager['hasIdentityChanged']('test@example.com', 'TEST@EXAMPLE.COM');
1333+
expect(result).toBe(true);
1334+
});
1335+
});
12691336
});

0 commit comments

Comments
 (0)