feat: meter AI usage
CI and Deploy / test (push) Failing after 58s
CI and Deploy / deploy (push) Has been skipped

This commit is contained in:
cesnimda
2026-07-30 22:39:24 +02:00
parent f8466c2ebc
commit c08232b9d7
15 changed files with 2482 additions and 11 deletions
@@ -31,10 +31,17 @@ beforeEach(() => {
jest.clearAllMocks();
mockedApi.get.mockImplementation((url: string) => {
if (url.includes("/modules")) return Promise.resolve({ data: { modules: [], provider: "gemini" } } as any);
if (url === "/ai/usage") return Promise.resolve({ data: { currentMonth: { calls: 3, inputCharacters: 100, outputCharacters: 50, estimatedTokens: 38 }, allTime: { calls: 8, inputCharacters: 300, outputCharacters: 120, estimatedTokens: 105 } } } as any);
return Promise.resolve({ data: [] } as any); // history
});
});
test("shows transparent monthly usage", async () => {
renderPanel();
expect(await screen.findByText(/approximately/)).toHaveTextContent("3 runs");
expect(screen.getByText(/approximately/)).toHaveTextContent("38 tokens");
});
test("renders modules and generates a suggestion into history", async () => {
mockedApi.post.mockResolvedValueOnce({
data: { id: 1, module: "job-analysis", mode: null, title: "Job analysis", provider: "gemini", result: { text: "**Company**\nAcme" }, createdAtUtc: new Date().toISOString() },