40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
import { useAuthStore } from "../../src/stores/authStore";
|
|
import { createPinia, setActivePinia } from "pinia";
|
|
|
|
describe("Auth Store", () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia());
|
|
});
|
|
|
|
it("should initialize with no user", () => {
|
|
const store = useAuthStore();
|
|
expect(store.isAuthenticated).toBe(false);
|
|
expect(store.user).toBeNull();
|
|
});
|
|
|
|
it("should store user data on login", () => {
|
|
const store = useAuthStore();
|
|
|
|
// Mock user data
|
|
const mockUser = {
|
|
id: "123",
|
|
email: "test@example.com",
|
|
username: "testuser",
|
|
};
|
|
|
|
// In a real test, you'd mock the API call
|
|
// For now, just test the store structure
|
|
expect(store.user).toBeNull();
|
|
});
|
|
|
|
it("should clear user data on logout", () => {
|
|
const store = useAuthStore();
|
|
store.logout();
|
|
|
|
expect(store.isAuthenticated).toBe(false);
|
|
expect(store.user).toBeNull();
|
|
expect(store.accessToken).toBeNull();
|
|
});
|
|
});
|