50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { createPinia, setActivePinia } from "pinia";
|
|
|
|
type StorageLike = {
|
|
getItem: (key: string) => string | null;
|
|
setItem: (key: string, value: string) => void;
|
|
removeItem: (key: string) => void;
|
|
clear: () => void;
|
|
};
|
|
|
|
const createStorage = (): StorageLike => {
|
|
const data = new Map<string, string>();
|
|
return {
|
|
getItem: (key) => data.get(key) ?? null,
|
|
setItem: (key, value) => {
|
|
data.set(key, String(value));
|
|
},
|
|
removeItem: (key) => {
|
|
data.delete(key);
|
|
},
|
|
clear: () => {
|
|
data.clear();
|
|
},
|
|
};
|
|
};
|
|
|
|
describe("auth store logout", () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia());
|
|
Object.defineProperty(window, "localStorage", {
|
|
value: createStorage(),
|
|
configurable: true,
|
|
});
|
|
});
|
|
|
|
it("clears session lock state when logging out", async () => {
|
|
const { useAuthStore } = await import("./auth");
|
|
const { useSessionStore } = await import("./session");
|
|
const session = useSessionStore();
|
|
const auth = useAuthStore();
|
|
|
|
session.lock("token_invalid", "user@example.com", Date.now() + 60_000);
|
|
auth.logout();
|
|
|
|
expect(session.locked).toBe(false);
|
|
expect(session.lockReason).toBeNull();
|
|
expect(session.lockEmail).toBe("");
|
|
});
|
|
});
|