Skip to content

🔧 Tests lack database isolation — dashboard API test fails on seeded/shared DB #63

Description

@lgwacker

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions