test(api): add resetDb helper + per-test isolation (proof: sessions suite)
This commit is contained in:
21
apps/api/test/reset-db.test.ts
Normal file
21
apps/api/test/reset-db.test.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { db } from '../src/db/client';
|
||||
import { workSessions, user } from '../src/db/schema';
|
||||
import { resetDb, seedActivity, authToken } from './helpers';
|
||||
import { createApp } from '../src/app';
|
||||
|
||||
describe('resetDb', () => {
|
||||
beforeEach(resetDb);
|
||||
|
||||
it('clears domain and auth rows so counts start from zero', async () => {
|
||||
const app = createApp();
|
||||
await authToken(app, 'reset-a@example.com');
|
||||
await seedActivity('Zagen');
|
||||
expect((await db.select().from(user)).length).toBeGreaterThan(0);
|
||||
|
||||
await resetDb();
|
||||
|
||||
expect(await db.select().from(user)).toHaveLength(0);
|
||||
expect(await db.select().from(workSessions)).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user