fix(test): mock db/index.js in unit tests that import API modules

Five unit tests crashed because they imported modules that transitively
reached db/index.ts, which eagerly calls `new Database()` at module load
time. Added vi.mock for db/index.js matching the pattern used by 16
other passing API unit tests.

Moved cleanup.test.ts to tests/integration/ since it uses a real SQLite
database, runs migrations, and inserts rows.
This commit is contained in:
SnapOtter
2026-06-09 23:34:36 +08:00
parent 60e3ac2210
commit 5b3b3c7632
6 changed files with 41 additions and 7 deletions
+7 -1
View File
@@ -8,7 +8,13 @@
import type { Permission, Role } from "@snapotter/shared";
import { describe, expect, it, vi } from "vitest";
// Mock the auth plugin to avoid transitively opening a SQLite connection
vi.mock("../../../apps/api/src/db/index.js", () => ({
db: {
select: () => ({ from: () => ({ where: () => ({ get: () => null }) }) }),
},
schema: { roles: {}, settings: {} },
}));
vi.mock("../../../apps/api/src/plugins/auth.js", () => ({
getAuthUser: () => null,
}));