fix frontend phase0 bugs
This commit is contained in:
@@ -96,8 +96,9 @@ describe('useUserStore', () => {
|
||||
})
|
||||
|
||||
describe('setUser', () => {
|
||||
it('sets user info in store and localStorage', () => {
|
||||
it('persists to localStorage when remember=true', () => {
|
||||
const store = useUserStore()
|
||||
store.setToken('h.p.s', 'r.p.s', true)
|
||||
const userInfo = { id: 1, username: 'test', email: 't@t.com', role: 'user', status: 1 }
|
||||
|
||||
store.setUser(userInfo)
|
||||
@@ -108,7 +109,17 @@ describe('useUserStore', () => {
|
||||
expect(JSON.parse(localStorage.getItem('user')!)).toEqual(userInfo)
|
||||
})
|
||||
|
||||
it('does not write to localStorage when remember=false', () => {
|
||||
it('does not persist to localStorage by default (remember=false)', () => {
|
||||
const store = useUserStore()
|
||||
const userInfo = { id: 1, username: 'test', email: 't@t.com', role: 'user', status: 1 }
|
||||
|
||||
store.setUser(userInfo)
|
||||
|
||||
expect(store.user).toEqual(userInfo)
|
||||
expect(localStorage.getItem('user')).toBeNull()
|
||||
})
|
||||
|
||||
it('does not write to localStorage after setToken(remember=false)', () => {
|
||||
const store = useUserStore()
|
||||
store.setToken('h.p.s', 'r.p.s', false)
|
||||
|
||||
@@ -136,6 +147,19 @@ describe('useUserStore', () => {
|
||||
expect(localStorage.getItem('refresh_token')).toBeNull()
|
||||
expect(localStorage.getItem('user')).toBeNull()
|
||||
})
|
||||
|
||||
it('resets _remember so subsequent setUser does not persist', () => {
|
||||
const store = useUserStore()
|
||||
store.setToken('h.p.s', 'r.p.s', true)
|
||||
store.setUser({ id: 1, username: 'a', email: 'a@a.com', role: 'admin', status: 1 })
|
||||
expect(localStorage.getItem('user')).not.toBeNull()
|
||||
|
||||
store.logout()
|
||||
store.setUser({ id: 2, username: 'b', email: 'b@b.com', role: 'user', status: 1 })
|
||||
|
||||
expect(store.user?.username).toBe('b')
|
||||
expect(localStorage.getItem('user')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('fetchCurrentUser', () => {
|
||||
|
||||
Reference in New Issue
Block a user