Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(auth): scope analytics reset assertion to browser client
  • Loading branch information
LiorMazig committed Sep 10, 2026
commit f9498cf7ae0e43f6c5e3ffd4a392e2ddb625f14f
27 changes: 19 additions & 8 deletions tests/unit/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,24 @@ describe('Auth Module', () => {
expect(scope.isDone()).toBe(true);
});

test('setToken() clears the analytics session context', () => {
const analyticsState = getSharedInstance('analytics', () => ({}));
analyticsState.sessionContext = { user_id: 'anonymous-user', session_id: 's1' };

base44.auth.setToken('new-access-token', false);

expect(analyticsState.sessionContext).toBeNull();
test('setToken() clears the shared browser analytics session context', () => {
vi.stubGlobal('window', {
location: { origin: appBaseUrl, pathname: '/', search: '' },
localStorage: { getItem: () => null },
});
let browserClient;
try {
browserClient = createClient({ serverUrl, appId, appBaseUrl, analytics: { enabled: false } });
const analyticsState = getSharedInstance('analytics', () => ({}));
analyticsState.sessionContext = { user_id: 'anonymous-user', session_id: 's1' };

browserClient.auth.setToken('new-access-token', false);

expect(analyticsState.sessionContext).toBeNull();
} finally {
browserClient?.cleanup();
vi.unstubAllGlobals();
}
});
});

Expand Down Expand Up @@ -967,4 +978,4 @@ describe('Auth Module', () => {
global.window = originalWindow;
});
});
});
});
Loading