Skip to content

Commit 4ceae33

Browse files
authored
[MOB-10123]: Clear Anon Data When Replay is False (#478)
* clear anon data on user initialization * clear anon data even if replay is false * update tests * oop * Update authorization.ts
1 parent ebd61bf commit 4ceae33

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/anonymousUserTracking/tests/userMergeScenarios.test.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ describe('UserMergeScenariosTests', () => {
135135
const removeItemCalls = localStorageMock.removeItem.mock.calls.filter(
136136
(call) => call[0] === SHARED_PREFS_EVENT_LIST_KEY
137137
);
138-
// count 1 means it did not remove item and so syncEvents was NOT called
139-
// because removeItem gets called one time for the key in case of logout
140-
expect(removeItemCalls.length).toBe(1);
138+
// count 2 is because we want to remove the anon user and remove anon details
139+
expect(removeItemCalls.length).toBe(2);
141140
const mergePostRequestData = mockRequest.history.post.find(
142141
(req) => req.url === ENDPOINT_MERGE_USER
143142
);
@@ -175,7 +174,6 @@ describe('UserMergeScenariosTests', () => {
175174
(call) => call[0] === SHARED_PREFS_EVENT_LIST_KEY
176175
);
177176
// count 2 means it removed items and so syncEvents was called
178-
179177
// because removeItem gets called one time for
180178
// the key in case of logout and 2nd time on syncevents
181179
expect(removeItemCalls.length).toBe(2);
@@ -574,9 +572,8 @@ describe('UserMergeScenariosTests', () => {
574572
const removeItemCalls = localStorageMock.removeItem.mock.calls.filter(
575573
(call) => call[0] === SHARED_PREFS_EVENT_LIST_KEY
576574
);
577-
// count 1 means it did not remove item and so syncEvents was NOT called
578-
// because removeItem gets called one time for the key in case of logout
579-
expect(removeItemCalls.length).toBe(1);
575+
// count 2 is because we want to remove the anon user and remove anon details
576+
expect(removeItemCalls.length).toBe(2);
580577
const mergePostRequestData = mockRequest.history.post.find(
581578
(req) => req.url === ENDPOINT_MERGE_USER
582579
);

src/authorization/authorization.ts

+8
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ export function initialize(
489489
initializeEmailUser(email);
490490
if (replay) {
491491
syncEvents();
492+
} else {
493+
anonUserManager.removeAnonSessionCriteriaData();
492494
}
493495
return Promise.resolve();
494496
}
@@ -517,6 +519,8 @@ export function initialize(
517519
initializeUserId(userId);
518520
if (replay) {
519521
syncEvents();
522+
} else {
523+
anonUserManager.removeAnonSessionCriteriaData();
520524
}
521525
return Promise.resolve();
522526
}
@@ -871,6 +875,8 @@ export function initialize(
871875
initializeEmailUser(email);
872876
if (replay) {
873877
syncEvents();
878+
} else {
879+
anonUserManager.removeAnonSessionCriteriaData();
874880
}
875881
return token;
876882
}
@@ -914,6 +920,8 @@ export function initialize(
914920
initializeUserId(userId);
915921
if (replay) {
916922
syncEvents();
923+
} else {
924+
anonUserManager.removeAnonSessionCriteriaData();
917925
}
918926
return token;
919927
}

0 commit comments

Comments
 (0)