import { describe, expect, it, beforeEach } from "vitest" import { hasSession, loadSession, signIn, signOut } from "./session" describe("session", () => { beforeEach(() => { localStorage.clear() }) it("starts unauthenticated", () => { expect(loadSession()).toBeNull() expect(hasSession()).toBe(false) }) it("rejects empty credentials", async () => { await expect(signIn("", "")).rejects.toThrow(/required/i) await expect(signIn("not-an-email", "pw")).rejects.toThrow(/valid email/i) expect(hasSession()).toBe(false) }) it("creates a session on sign-in and clears on sign-out", async () => { const session = await signIn("alice@example.com", "hunter2") expect(session.email).toBe("alice@example.com") expect(session.token).toMatch(/^dev-/) expect(hasSession()).toBe(true) signOut() expect(loadSession()).toBeNull() expect(hasSession()).toBe(false) }) })