@@ -441,36 +441,42 @@ describe('helpers utility functions', () => {
441441 } ) ;
442442
443443 describe ( 'hasNonExpiredAuthToken' , ( ) => {
444- it ( 'should return true when token is not defined' , ( ) => {
445- vi . mocked ( getLocalStorageItem ) . mockReturnValue ( null ) ;
446- expect ( hasNonExpiredAuthToken ( ) ) . toBe ( true ) ;
444+ // hasNonExpiredAuthToken reads directly from window.localStorage, using
445+ // the SDK's LOCAL_STORAGE_KEYS ('axd_token' / 'axd_token_expires').
446+ const AUTH_TOKEN_KEY = 'axd_token' ;
447+ const TOKEN_EXPIRY_KEY = 'axd_token_expires' ;
448+
449+ it ( 'should return false when token is not defined' , ( ) => {
450+ window . localStorage . clear ( ) ;
451+ expect ( hasNonExpiredAuthToken ( ) ) . toBe ( false ) ;
447452 } ) ;
448453
449454 it ( 'should return true when token expiry is not defined' , ( ) => {
450- vi . mocked ( getLocalStorageItem ) . mockReturnValueOnce ( 'valid-token' ) . mockReturnValueOnce ( null ) ;
455+ window . localStorage . clear ( ) ;
456+ window . localStorage . setItem ( AUTH_TOKEN_KEY , 'valid-token' ) ;
451457 expect ( hasNonExpiredAuthToken ( ) ) . toBe ( true ) ;
452458 } ) ;
453459
454460 it ( 'should return false when token is expired' , ( ) => {
461+ window . localStorage . clear ( ) ;
455462 const pastDate = new Date ( Date . now ( ) - 1000 ) . toISOString ( ) ;
456- vi . mocked ( getLocalStorageItem )
457- . mockReturnValueOnce ( 'valid-token' )
458- . mockReturnValueOnce ( pastDate ) ;
463+ window . localStorage . setItem ( AUTH_TOKEN_KEY , 'valid-token' ) ;
464+ window . localStorage . setItem ( TOKEN_EXPIRY_KEY , pastDate ) ;
459465 expect ( hasNonExpiredAuthToken ( ) ) . toBe ( false ) ;
460466 } ) ;
461467
462468 it ( 'should return true when token is not expired' , ( ) => {
469+ window . localStorage . clear ( ) ;
463470 const futureDate = new Date ( Date . now ( ) + 1000 * 60 * 60 ) . toISOString ( ) ;
464- vi . mocked ( getLocalStorageItem )
465- . mockReturnValueOnce ( 'valid-token' )
466- . mockReturnValueOnce ( futureDate ) ;
471+ window . localStorage . setItem ( AUTH_TOKEN_KEY , 'valid-token' ) ;
472+ window . localStorage . setItem ( TOKEN_EXPIRY_KEY , futureDate ) ;
467473 expect ( hasNonExpiredAuthToken ( ) ) . toBe ( true ) ;
468474 } ) ;
469475
470476 it ( 'should return false for invalid date' , ( ) => {
471- vi . mocked ( getLocalStorageItem )
472- . mockReturnValueOnce ( 'valid-token' )
473- . mockReturnValueOnce ( 'invalid-date' ) ;
477+ window . localStorage . clear ( ) ;
478+ window . localStorage . setItem ( AUTH_TOKEN_KEY , 'valid-token' ) ;
479+ window . localStorage . setItem ( TOKEN_EXPIRY_KEY , 'invalid-date' ) ;
474480 expect ( hasNonExpiredAuthToken ( ) ) . toBe ( false ) ;
475481 } ) ;
476482 } ) ;
0 commit comments