mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-07-21 10:15:47 +00:00
* test(frontend): migrate unit tests to rstest * docs: updates AGENTS.md * test(frontend): fix rstest lint formatting
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { beforeEach, expect, test, rs } from "@rstest/core";
|
|
|
|
const fetchWithAuth = rs.fn();
|
|
|
|
rs.mock("@/core/api/fetcher", () => ({
|
|
fetch: fetchWithAuth,
|
|
}));
|
|
|
|
beforeEach(() => {
|
|
fetchWithAuth.mockReset();
|
|
});
|
|
|
|
test("fetchThreadTokenUsage uses shared auth fetch without JSON GET headers", async () => {
|
|
fetchWithAuth.mockResolvedValue({
|
|
ok: true,
|
|
json: async () => ({
|
|
thread_id: "thread-1",
|
|
total_input_tokens: 3,
|
|
total_output_tokens: 4,
|
|
total_tokens: 7,
|
|
total_runs: 1,
|
|
by_model: { unknown: { tokens: 7, runs: 1 } },
|
|
by_caller: {
|
|
lead_agent: 0,
|
|
subagent: 0,
|
|
middleware: 0,
|
|
},
|
|
}),
|
|
});
|
|
|
|
const { fetchThreadTokenUsage } = await import("@/core/threads/api");
|
|
|
|
await expect(fetchThreadTokenUsage("thread-1")).resolves.toMatchObject({
|
|
thread_id: "thread-1",
|
|
total_tokens: 7,
|
|
});
|
|
|
|
expect(fetchWithAuth).toHaveBeenCalledWith(
|
|
expect.stringContaining("/api/threads/thread-1/token-usage"),
|
|
{
|
|
method: "GET",
|
|
},
|
|
);
|
|
});
|
|
|
|
test("fetchThreadTokenUsage returns null for unavailable token usage", async () => {
|
|
fetchWithAuth.mockResolvedValue({
|
|
ok: false,
|
|
status: 404,
|
|
});
|
|
|
|
const { fetchThreadTokenUsage } = await import("@/core/threads/api");
|
|
|
|
await expect(fetchThreadTokenUsage("thread-1")).resolves.toBeNull();
|
|
});
|