Summary
The dashboard API route test (src/app/api/dashboard/__tests__/route.test.ts) fails when the development database contains data from seeding or previous test runs because it directly mutates the shared SQLite database without isolation.
Findings
Running npm test with a seeded database produces:
FAIL src/app/api/dashboard/__tests__/route.test.ts
● Dashboard API Route › Data freshness › should return updated position count after creating a new position
expect(received).toBe(expected)
Expected: 12
Received: 13
The test calls GET() and POST_POSITION() directly, which interact with data/tiopatinhas.db. After seeding (6 positions) and previous test runs, the database accumulates records, causing assertions like expect(updatedData.summary.positionCount).toBe(initialPositionCount + 1) to fail.
Current database state after seeding + tests:
- Positions: 14
- Operations: 17
Expected
Tests should be isolated and deterministic:
- Use an in-memory or temporary test database
- Clean up test data after each test
- Use transactions that are rolled back
- Or mock the database layer entirely
Affected tests
src/app/api/dashboard/__tests__/route.test.ts
- Potentially other API route tests that write to the database
Summary
The dashboard API route test (
src/app/api/dashboard/__tests__/route.test.ts) fails when the development database contains data from seeding or previous test runs because it directly mutates the shared SQLite database without isolation.Findings
Running
npm testwith a seeded database produces:The test calls
GET()andPOST_POSITION()directly, which interact withdata/tiopatinhas.db. After seeding (6 positions) and previous test runs, the database accumulates records, causing assertions likeexpect(updatedData.summary.positionCount).toBe(initialPositionCount + 1)to fail.Current database state after seeding + tests:
Expected
Tests should be isolated and deterministic:
Affected tests
src/app/api/dashboard/__tests__/route.test.ts