← back to Govarbitrage

src/lib/money-math-visibility.test.ts

28 lines

import { describe, expect, it } from "vitest";
import { moneyMathVisible } from "./current-user";
import { TIERS, TIER_ORDER } from "./tiers";

// Guideline 5.6 regression lock (TK-10279). The app was rejected because
// money-math visibility keyed off an undisclosed client signal (the presence of
// any Authorization header). The fix removed all client-sniffing: visibility is
// a pure function of the resolved tier. These tests fail the moment anyone
// reintroduces a client/header-dependent branch or re-gates the FREE tier.
describe("money-math visibility (Guideline 5.6 lock)", () => {
  it("moneyMathVisible depends ONLY on the tier argument — no request/header input", () => {
    // A pure function of one argument cannot vary by client. Same tier in ⇒
    // same answer out, every call.
    expect(moneyMathVisible.length).toBe(1);
  });

  it("the FREE tier shows the full analysis, so a fresh anonymous install is complete", async () => {
    expect(TIERS.FREE.limits.showMoneyMath).toBe(true);
    expect(await moneyMathVisible("FREE")).toBe(true);
  });

  it("every tier shows money-math identically (nothing is client-specific)", async () => {
    for (const t of TIER_ORDER) {
      expect(await moneyMathVisible(t)).toBe(true);
    }
  });
});