test(api): add resetDb helper + per-test isolation (proof: sessions suite)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { Hono } from 'hono';
|
||||
import { auth } from '../src/auth';
|
||||
import { db } from '../src/db/client';
|
||||
import { activities } from '../src/db/schema';
|
||||
import { account, activities, session, user, verification, workSessions } from '../src/db/schema';
|
||||
|
||||
const PASSWORD = 'sterk-wachtwoord-123';
|
||||
const json = { 'content-type': 'application/json' };
|
||||
@@ -44,6 +44,18 @@ export function bearer(token: string): Record<string, string> {
|
||||
return { authorization: `Bearer ${token}`, 'content-type': 'application/json' };
|
||||
}
|
||||
|
||||
// Wipe all data rows (schema stays; migration already ran once in setup.ts).
|
||||
// Lets a domain suite start from an empty DB in beforeEach instead of inheriting
|
||||
// rows from earlier test files (removes the accumulate-and-scope fragility).
|
||||
export async function resetDb(): Promise<void> {
|
||||
await db.delete(workSessions);
|
||||
await db.delete(session);
|
||||
await db.delete(account);
|
||||
await db.delete(verification);
|
||||
await db.delete(user);
|
||||
await db.delete(activities);
|
||||
}
|
||||
|
||||
// Insert an activity straight into the DB (test setup that should not depend on authz).
|
||||
export async function seedActivity(
|
||||
name: string,
|
||||
|
||||
Reference in New Issue
Block a user