test(api): add resetDb helper + per-test isolation (proof: sessions suite)

This commit is contained in:
Bas van Rossem
2026-07-22 11:28:01 +02:00
parent 3c79e51e99
commit f872daf117
3 changed files with 40 additions and 3 deletions

View File

@@ -1,13 +1,15 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect, beforeEach } from 'vitest';
import { createApp } from '../src/app';
import { db } from '../src/db/client';
import { workSessions } from '../src/db/schema';
import { eq } from 'drizzle-orm';
import { authToken, bearer, seedActivity } from './helpers';
import { authToken, bearer, seedActivity, resetDb } from './helpers';
const json = { 'content-type': 'application/json' };
describe('session lifecycle', () => {
beforeEach(resetDb);
it('401s start/stop/discard without a token', async () => {
const app = createApp();
@@ -334,6 +336,8 @@ describe('session lifecycle', () => {
});
describe('session reads', () => {
beforeEach(resetDb);
it('401s GET /api/sessions and /api/sessions/active without a token', async () => {
const app = createApp();