Skip to content

Commit

Permalink
[MOB-10123]: Clear Anon Data When Replay is False (#478)
Browse files Browse the repository at this point in the history
* clear anon data on user initialization

* clear anon data even if replay is false

* update tests

* oop

* Update authorization.ts
mprew97 authored Nov 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent ebd61bf commit 4ceae33
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/anonymousUserTracking/tests/userMergeScenarios.test.ts
Original file line number Diff line number Diff line change
@@ -135,9 +135,8 @@ describe('UserMergeScenariosTests', () => {
const removeItemCalls = localStorageMock.removeItem.mock.calls.filter(
(call) => call[0] === SHARED_PREFS_EVENT_LIST_KEY
);
// count 1 means it did not remove item and so syncEvents was NOT called
// because removeItem gets called one time for the key in case of logout
expect(removeItemCalls.length).toBe(1);
// count 2 is because we want to remove the anon user and remove anon details
expect(removeItemCalls.length).toBe(2);
const mergePostRequestData = mockRequest.history.post.find(
(req) => req.url === ENDPOINT_MERGE_USER
);
@@ -175,7 +174,6 @@ describe('UserMergeScenariosTests', () => {
(call) => call[0] === SHARED_PREFS_EVENT_LIST_KEY
);
// count 2 means it removed items and so syncEvents was called

// because removeItem gets called one time for
// the key in case of logout and 2nd time on syncevents
expect(removeItemCalls.length).toBe(2);
@@ -574,9 +572,8 @@ describe('UserMergeScenariosTests', () => {
const removeItemCalls = localStorageMock.removeItem.mock.calls.filter(
(call) => call[0] === SHARED_PREFS_EVENT_LIST_KEY
);
// count 1 means it did not remove item and so syncEvents was NOT called
// because removeItem gets called one time for the key in case of logout
expect(removeItemCalls.length).toBe(1);
// count 2 is because we want to remove the anon user and remove anon details
expect(removeItemCalls.length).toBe(2);
const mergePostRequestData = mockRequest.history.post.find(
(req) => req.url === ENDPOINT_MERGE_USER
);
8 changes: 8 additions & 0 deletions src/authorization/authorization.ts
Original file line number Diff line number Diff line change
@@ -489,6 +489,8 @@ export function initialize(
initializeEmailUser(email);
if (replay) {
syncEvents();
} else {
anonUserManager.removeAnonSessionCriteriaData();
}
return Promise.resolve();
}
@@ -517,6 +519,8 @@ export function initialize(
initializeUserId(userId);
if (replay) {
syncEvents();
} else {
anonUserManager.removeAnonSessionCriteriaData();
}
return Promise.resolve();
}
@@ -871,6 +875,8 @@ export function initialize(
initializeEmailUser(email);
if (replay) {
syncEvents();
} else {
anonUserManager.removeAnonSessionCriteriaData();
}
return token;
}
@@ -914,6 +920,8 @@ export function initialize(
initializeUserId(userId);
if (replay) {
syncEvents();
} else {
anonUserManager.removeAnonSessionCriteriaData();
}
return token;
}

0 comments on commit 4ceae33

Please sign in to comment.