import { describe, expect, it } from "vitest" import { formatBalanceError, formatCredits, readFoldOpen } from "../src/format" describe("formatCredits", () => { it("formats with two decimals", () => { expect(formatCredits(5.309411174)).toBe("5.31") }) it("formats zero", () => { expect(formatCredits(0)).toBe("0.00") }) it("returns a dash for non-finite input", () => { expect(formatCredits(Number.NaN)).toBe("-") }) }) describe("formatBalanceError", () => { it("renders each error kind", () => { expect(formatBalanceError({ kind: "unauthorized" })).toContain("invalide") expect(formatBalanceError({ kind: "network" })).toContain("réseau") expect(formatBalanceError({ kind: "missing-header", status: 400 })).toContain("400") expect(formatBalanceError({ kind: "no-credential", reason: "missing" })).toContain("GreenPT") }) }) describe("readFoldOpen", () => { it("defaults to open when the KV store is absent", () => { expect(readFoldOpen(undefined)).toBe(true) }) it("reads a persisted boolean", () => { expect(readFoldOpen({ get: () => false })).toBe(false) }) it("falls back when the stored value is not a boolean", () => { expect(readFoldOpen({ get: () => "nope" })).toBe(true) }) it("survives a throwing KV store", () => { expect( readFoldOpen({ get: () => { throw new Error("kv down") }, }), ).toBe(true) }) })