fix(admin): sum today's AI spend on each account's own local day

This commit is contained in:
Marc-André Bombeck committed 2026-10-11 13:50:17 +02:00
1 parent 5dbc6fcec1
commit 3c6150e837
13 files changed
+187 -51

No files matched your search

@@ -42,24 +42,26 @@ function render(data: object | null) {
}
describe("<ProviderHealthSection> — today's spend by cost owner", () => {
it("shows both figures and the day they belong to", () => {
it("shows both figures, the account count, and which day they count", () => {
const html = render({
providers: [],
spendToday: {
dateKey: "2026-09-11",
totalTokens: 1_240_000,
operatorTokens: 151_200,
accounts: 3,
},
});
expect(html).toContain("2026-09-11");
expect(html).toContain("1,240,000");
expect(html).toContain("151,200");
expect(html).toContain("accounts with spend: 3");
// Each account's own day, not one date for the whole instance.
expect(html).toContain("each account&#x27;s own calendar day");
});
it("renders a zero day rather than hiding the readout", () => {
const html = render({
providers: [],
spendToday: { dateKey: "2026-09-11", totalTokens: 0, operatorTokens: 0 },
spendToday: { totalTokens: 0, operatorTokens: 0, accounts: 0 },
});
expect(html).toContain('data-slot="ai-spend-today"');
});
@@ -34,10 +34,11 @@ import { formatDateTime } from "@/lib/format";
* the users' own plans. The operator ceiling is enforced against the second
* figure, so both belong on screen.
*/
/** Summed over every account's own current day, the day its ceilings use. */
interface SpendToday {
dateKey: string;
totalTokens: number;
operatorTokens: number;
accounts: number;
}
interface ProviderHealthRow {
@@ -107,7 +108,7 @@ export function ProviderHealthSection() {
{spendToday ? (
<p className="text-muted-foreground text-sm" data-slot="ai-spend-today">
{t("admin.providerHealth.spendToday", {
date: spendToday.dateKey,
accounts: groupDigits(spendToday.accounts),
total: groupDigits(spendToday.totalTokens),
operator: groupDigits(spendToday.operatorTokens),
})}