mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-10 10:14:01 +00:00
* feat(providers): auto-discover usage billing * feat(ui): show provider plans and billing * fix(ui): translate provider billing labels
79 lines
1.9 KiB
TypeScript
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,
|
|
});
|
|
});
|
|
});
|