Files
João Salavisa 8b21af3296 fix(stats): key Top Agents usage by model and stop dropping each range's first day (#2510)
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 19:43:46 +01:00

26 lines
834 B
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const fetchJsonMock = vi.hoisted(() => vi.fn());
vi.mock("../client", () => ({
fetchJson: fetchJsonMock,
}));
import { fetchModelUsage } from "./stats-api";
describe("fetchModelUsage", () => {
beforeEach(() => fetchJsonMock.mockReset());
it("requests the model-usage endpoint with the selected range", async () => {
const response = [{ model: "opus", session_count: 2, turn_count: 4, total_duration_ms: 100 }];
const options = { cache: "no-store" as const };
fetchJsonMock.mockResolvedValue(response);
await expect(fetchModelUsage("workspace-1", options, "month")).resolves.toEqual(response);
expect(fetchJsonMock).toHaveBeenCalledWith(
"/api/v1/workspaces/workspace-1/stats/model-usage?range=month",
options,
);
});
});