Files
openclaw/src/status/codex-synthetic-usage.test.ts
Peter Steinberger 07e2d633cc feat: show auto-detected provider plans and billing (#100520)
* feat(providers): auto-discover usage billing

* feat(ui): show provider plans and billing

* fix(ui): translate provider billing labels
2026-07-06 04:53:09 +01:00

79 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { mergeUsageSummaries } from "./codex-synthetic-usage.js";
describe("mergeUsageSummaries", () => {
it("preserves OAuth plan and billing when synthetic Codex windows win", () => {
const merged = mergeUsageSummaries(
{
updatedAt: 1,
providers: [
{
provider: "openai",
displayName: "OpenAI",
plan: "Plus",
windows: [{ label: "Week", usedPercent: 40 }],
billing: [{ type: "balance", amount: 12.5, unit: "credits" }],
},
],
},
{
updatedAt: 2,
providers: [
{
provider: "openai",
displayName: "Codex",
windows: [{ label: "5h", usedPercent: 10 }],
},
],
},
);
expect(merged).toEqual({
updatedAt: 1,
providers: [
{
provider: "openai",
displayName: "Codex",
plan: "Plus",
windows: [{ label: "5h", usedPercent: 10 }],
billing: [{ type: "balance", amount: 12.5, unit: "credits" }],
error: undefined,
},
],
});
});
it("ranks billing-only snapshots above errors", () => {
const merged = mergeUsageSummaries(
{
updatedAt: 1,
providers: [
{
provider: "openai",
displayName: "OpenAI",
windows: [],
billing: [{ type: "balance", amount: 4, unit: "credits" }],
},
],
},
{
updatedAt: 2,
providers: [
{
provider: "openai",
displayName: "Codex",
windows: [],
error: "Unavailable",
},
],
},
);
expect(merged.providers[0]).toMatchObject({
displayName: "OpenAI",
billing: [{ type: "balance", amount: 4, unit: "credits" }],
error: undefined,
});
});
});