test(api): cover assistant task reads and creation

This commit is contained in:
2026-04-01 00:07:42 +02:00
parent 5fae007a3b
commit db03d1208f
7 changed files with 494 additions and 0 deletions
@@ -0,0 +1,52 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { SystemRole } from "@capakraken/shared";
import {
createToolContext,
executeTool,
withUserLookup,
} from "./assistant-tools-task-workflow-test-helpers.js";
describe("assistant task counts tool", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("returns task counts for the current user through the real router path", async () => {
const db = withUserLookup({
notification: {
groupBy: vi.fn().mockResolvedValue([
{ taskStatus: "OPEN", _count: 4 },
{ taskStatus: "DONE", _count: 2 },
]),
count: vi.fn().mockResolvedValue(3),
},
});
const ctx = createToolContext(db, SystemRole.USER);
const result = await executeTool("get_task_counts", JSON.stringify({}), ctx);
expect(db.notification.groupBy).toHaveBeenCalledWith({
by: ["taskStatus"],
where: {
OR: [{ userId: "user_1" }, { assigneeId: "user_1" }],
category: { in: ["TASK", "APPROVAL"] },
},
_count: true,
});
expect(db.notification.count).toHaveBeenCalledWith({
where: {
OR: [{ userId: "user_1" }, { assigneeId: "user_1" }],
category: { in: ["TASK", "APPROVAL"] },
taskStatus: { in: ["OPEN", "IN_PROGRESS"] },
dueDate: { lt: expect.any(Date) },
},
});
expect(JSON.parse(result.content)).toEqual({
open: 4,
inProgress: 0,
done: 2,
dismissed: 0,
overdue: 3,
});
});
});