Skip to content

Commit fd3aba5

Browse files
refactor(test): move reauthenticate missing-credentials test into SessionTest
Replaces the standalone ReauthenticationTest file with a single focused test in the existing SessionTest suite. Calls reauthenticate() directly (no API stack needed) — after beforeEach Onyx.clear(), NetworkStore credentials are null, which is the exact condition the fix guards against. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 08eacb1 commit fd3aba5

2 files changed

Lines changed: 17 additions & 94 deletions

File tree

tests/actions/SessionTest.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {setHasRadio} from '@libs/NetworkState';
1616
import PushNotification from '@libs/Notification/PushNotification';
1717
// This lib needs to be imported, but it has nothing to export since all it contains is an Onyx connection
1818
import '@libs/Notification/PushNotification/subscribeToPushNotifications';
19+
import reauthenticate from '@libs/Reauthentication';
1920
import CONFIG from '@src/CONFIG';
2021
import CONST from '@src/CONST';
2122
import * as SessionUtil from '@src/libs/actions/Session';
@@ -62,6 +63,22 @@ beforeEach(() => {
6263
});
6364

6465
describe('Session', () => {
66+
test('reauthenticate redirects to sign in with "No credentials available" when credentials are missing', async () => {
67+
// Given no signed-in user — beforeEach calls Onyx.clear(), so NetworkStore's credentials are null
68+
69+
const redirectToSignInSpy = jest.spyOn(SignInRedirect, 'default').mockImplementation(() => Promise.resolve());
70+
71+
// When reauthenticate is called with no credentials stored
72+
const result = await reauthenticate('TestCommand');
73+
await waitForBatchedUpdates();
74+
75+
// Then it should redirect to sign in instead of attempting to call Authenticate with undefined credentials
76+
expect(result).toBe(false);
77+
expect(redirectToSignInSpy).toHaveBeenCalledWith('No credentials available');
78+
79+
redirectToSignInSpy.mockRestore();
80+
});
81+
6582
test('Authenticate is called with saved credentials when a session expires', async () => {
6683
// Given a test user and set of authToken with subscriptions to session and credentials
6784
const TEST_USER_LOGIN = 'test@testguy.com';

tests/unit/libs/ReauthenticationTest.ts

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)