first commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { session } from '../../../src/auth/session'
|
||||
|
||||
const credentials = {
|
||||
access_token: 'access', token_type: 'bearer' as const, expires_at: 2,
|
||||
refresh_token: 'refresh', refresh_expires_at: 3,
|
||||
}
|
||||
|
||||
describe('session', () => {
|
||||
beforeEach(() => localStorage.clear())
|
||||
|
||||
it('stores and replaces the complete credential set atomically', () => {
|
||||
const listener = vi.fn()
|
||||
const unsubscribe = session.subscribe(listener)
|
||||
session.set(credentials)
|
||||
expect(session.get()).toEqual(credentials)
|
||||
expect(JSON.parse(localStorage.getItem('safety-session') || 'null')).toEqual(credentials)
|
||||
expect(listener).toHaveBeenCalledOnce()
|
||||
unsubscribe()
|
||||
})
|
||||
|
||||
it('clears credentials and pending refresh state together', () => {
|
||||
localStorage.setItem('safety-session', JSON.stringify(credentials))
|
||||
localStorage.setItem('safety-refresh-pending', 'secret')
|
||||
localStorage.setItem('safety-refresh-after', '2')
|
||||
localStorage.setItem('safety-last-activity-at', '1')
|
||||
session.clear()
|
||||
expect(localStorage.length).toBe(0)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user