kaneo (minimalist kanban) fork to experiment adding a tangled integration
github.com/usekaneo/kaneo
1import type { Session, User } from "better-auth/types";
2import { vi } from "vitest";
3import { auth } from "../../../apps/api/src/auth";
4
5function createSession(userId: string): Session {
6 const now = new Date();
7
8 return {
9 id: `session-${userId}`,
10 token: `token-${userId}`,
11 userId,
12 expiresAt: new Date(now.getTime() + 60 * 60 * 1000),
13 createdAt: now,
14 updatedAt: now,
15 ipAddress: null,
16 userAgent: null,
17 };
18}
19
20export function mockAuthenticatedSession(user: User) {
21 return vi.spyOn(auth.api, "getSession").mockResolvedValue({
22 session: createSession(user.id),
23 user,
24 });
25}
26
27export function mockAnonymousSession() {
28 return vi.spyOn(auth.api, "getSession").mockResolvedValue(null);
29}