import { describe, it, expect } from "vitest";
import { CATEGORIES, formatCategory } from "@/lib/categories";

describe("formatCategory", () => {
  it("capitalises single word", () => {
    expect(formatCategory("groceries")).toBe("Groceries");
  });
  it("capitalises and spaces underscore-separated words", () => {
    expect(formatCategory("home_goods")).toBe("Home Goods");
  });
  it("handles three-word categories", () => {
    expect(formatCategory("home_maintenance")).toBe("Home Maintenance");
  });
  it("handles cash_advance", () => {
    expect(formatCategory("cash_advance")).toBe("Cash Advance");
  });
  it("handles personal_care", () => {
    expect(formatCategory("personal_care")).toBe("Personal Care");
  });
  it("handles single-word categories without underscores", () => {
    expect(formatCategory("travel")).toBe("Travel");
    expect(formatCategory("fees")).toBe("Fees");
    expect(formatCategory("other")).toBe("Other");
  });
});

describe("CATEGORIES", () => {
  it("contains expected core categories", () => {
    const cats = CATEGORIES as readonly string[];
    expect(cats).toContain("groceries");
    expect(cats).toContain("dining");
    expect(cats).toContain("transport");
    expect(cats).toContain("health");
    expect(cats).toContain("other");
  });
  it("has no duplicates", () => {
    const cats = CATEGORIES as readonly string[];
    expect(new Set(cats).size).toBe(cats.length);
  });
  it("all entries are lowercase with only letters and underscores", () => {
    for (const cat of CATEGORIES) {
      expect(cat).toMatch(/^[a-z_]+$/);
    }
  });
  it("formatCategory produces unique display names", () => {
    const formatted = CATEGORIES.map(formatCategory);
    expect(new Set(formatted).size).toBe(formatted.length);
  });
});
