33 lines
752 B
TypeScript
33 lines
752 B
TypeScript
/**
|
|
* hooks/useJWT.ts — token / userId persistence over the secure StorageService.
|
|
*/
|
|
|
|
import {
|
|
AUTH_TOKEN_KEY,
|
|
USER_ID_KEY,
|
|
deleteAuthToken,
|
|
getAuthToken,
|
|
getUserId,
|
|
saveAuthToken,
|
|
saveUserId,
|
|
} from '@/hooks/useJWT'
|
|
|
|
describe('useJWT', () => {
|
|
it('stores, reads and deletes the auth token', async () => {
|
|
await saveAuthToken('token-123')
|
|
expect(await getAuthToken()).toBe('token-123')
|
|
|
|
await deleteAuthToken()
|
|
expect(await getAuthToken()).toBeNull()
|
|
})
|
|
|
|
it('stores and reads the user id', async () => {
|
|
await saveUserId('42')
|
|
expect(await getUserId()).toBe('42')
|
|
})
|
|
|
|
it('exposes the storage keys', () => {
|
|
expect(AUTH_TOKEN_KEY).toBe('authToken')
|
|
expect(USER_ID_KEY).toBe('userId')
|
|
})
|
|
})
|