import { describe, expect, it } from "vitest"; import type { Session } from "../../../shared/api/schemas"; import { isCurrentSessionSnapshot } from "./session-refresh"; const initialSession: Session = { account: { id: "01928f7a-1a2b-7c3d-8e4f-5a6b7c8d9e01", email: "owner@example.test", email_verified: true, scenario: "employer", onboarding_step: "completed", created_at: "2026-10-06T09:00:00Z", }, csrf_token: "abcdefghijklmnopqrstuvwxyz123456", }; describe("isCurrentSessionSnapshot", () => { it("accepts the same account and CSRF snapshot only while its cache generation is unchanged", () => { expect(isCurrentSessionSnapshot(initialSession, "success", 100, initialSession, 100)).toBe( true, ); expect(isCurrentSessionSnapshot(initialSession, "success", 101, initialSession, 100)).toBe( false, ); }); it("rejects a changed account or CSRF token before applying a delayed refresh", () => { const rotatedToken = { ...initialSession, csrf_token: "zyxwvutsrqponmlkjihgfedcba654321" }; const anotherAccount = { ...initialSession, account: { ...initialSession.account, id: "01928f7a-1a2b-7c3d-8e4f-5a6b7c8d9e02" }, }; expect(isCurrentSessionSnapshot(rotatedToken, "success", 100, initialSession, 100)).toBe(false); expect(isCurrentSessionSnapshot(anotherAccount, "success", 100, initialSession, 100)).toBe( false, ); }); });