@@ -16,6 +16,7 @@ import {setHasRadio} from '@libs/NetworkState';
1616import 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
1818import '@libs/Notification/PushNotification/subscribeToPushNotifications' ;
19+ import reauthenticate from '@libs/Reauthentication' ;
1920import CONFIG from '@src/CONFIG' ;
2021import CONST from '@src/CONST' ;
2122import * as SessionUtil from '@src/libs/actions/Session' ;
@@ -62,6 +63,22 @@ beforeEach(() => {
6263} ) ;
6364
6465describe ( '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' ;
0 commit comments