import { setActivePinia, createPinia } from 'pinia' import { beforeEach, describe, expect, it } from 'vitest' import { useAuthStore } from '@/stores/auth' describe('auth store', () => { beforeEach(() => { localStorage.clear() setActivePinia(createPinia()) }) it('starts unauthenticated', () => { const auth = useAuthStore() expect(auth.isAuthenticated).toBe(false) expect(auth.token).toBe(null) }) it('setToken stores token + username and authenticates', () => { const auth = useAuthStore() auth.setToken('jwt-xyz', 'admin') expect(auth.token).toBe('jwt-xyz') expect(auth.username).toBe('admin') expect(auth.isAuthenticated).toBe(true) expect(localStorage.getItem('token')).toBe('jwt-xyz') }) it('logout clears token + username', () => { const auth = useAuthStore() auth.setToken('jwt-xyz', 'admin') auth.logout() expect(auth.token).toBe(null) expect(auth.username).toBe(null) expect(auth.isAuthenticated).toBe(false) expect(localStorage.getItem('token')).toBe(null) }) })