import { clearCachedPolicy, getCachedPolicy, getHibpPolicy, setCachedPolicy } from "../hibp-cache"; beforeEach(() => { clearCachedPolicy(); }); describe("hibp policy cache", () => { it("starts empty", () => { expect(getCachedPolicy()).toBeNull(); }); it("round-trips a policy through set/get", () => { const p = { enabled: true, enforce: false, block_threshold: 5 }; setCachedPolicy(p); expect(getCachedPolicy()).toEqual(p); }); it("clear empties the cache", () => { setCachedPolicy({ enabled: true, enforce: true, block_threshold: 0 }); clearCachedPolicy(); expect(getCachedPolicy()).toBeNull(); }); it("getHibpPolicy falls back to a conservative default", () => { clearCachedPolicy(); const fallback = getHibpPolicy(); expect(fallback.enabled).toBe(true); expect(fallback.enforce).toBe(true); expect(fallback.block_threshold).toBe(1000); }); it("getHibpPolicy returns the cached entry when present", () => { const p = { enabled: false, enforce: false, block_threshold: 7 }; setCachedPolicy(p); expect(getHibpPolicy()).toEqual(p); }); });