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,37 @@
import { SystemRole } from "@capakraken/shared";
import type { ToolContext } from "../router/assistant-tools.js";
export function createToolContext(
db: Record<string, unknown>,
options?: {
userRole?: SystemRole;
},
): ToolContext {
const userRole = options?.userRole ?? SystemRole.ADMIN;
let effectiveDb: Record<string, unknown>;
effectiveDb = "$transaction" in db
? db
: {
...db,
$transaction: async (
callback: (tx: ToolContext["db"]) => Promise<unknown>,
) => callback(effectiveDb as ToolContext["db"]),
};
return {
db: effectiveDb as ToolContext["db"],
userId: "user_1",
userRole,
permissions: new Set(),
session: {
user: { email: "assistant@example.com", name: "Assistant User", image: null },
expires: "2026-03-29T00:00:00.000Z",
},
dbUser: {
id: "user_1",
systemRole: userRole,
permissionOverrides: null,
},
roleDefaults: null,
};
}