feat(04-01): install new deps + scaffold API test harness with Wave-0 RED stubs

- Add react-router@7, @dnd-kit/core, @dnd-kit/sortable, fractional-indexing to PWA
- Add fractional-indexing to API (rank generation server-side)
- ioredis NOT added (in-memory EventEmitter per RESEARCH Plan 02 justification)
- Create apps/api/test/setup.ts with afterEach DB cleanup for list tables
- Wire test.setupFiles in apps/api/vitest.config.ts
- Add 4 Wave-0 RED stub test files (LIST-01/02/03/04, D-04, D-11, D-07)
- All stubs run as todo, not import-error
This commit is contained in:
Lucas Berger
2026-06-09 11:49:10 -04:00
parent 95b13e6633
commit 39d4ec84c0
9 changed files with 241 additions and 2 deletions
+37
View File
@@ -0,0 +1,37 @@
/**
* Vitest global test setup for apps/api.
*
* Establishes shared test infrastructure for API tests:
* - DB pool access via the existing client.ts (DB_HOST/DB_NAME from env)
* - Per-test cleanup for list tables (truncate between tests so state is isolated)
*
* Usage:
* This file is referenced in vitest.config.ts via test.setupFiles.
* Pure-logic tests (listEmitter, fractional rank) do NOT require DB — the
* cleanup function is a no-op when the tables are empty.
*
* Environment:
* Set DB_HOST, DB_USER, DB_PASSWORD, DB_NAME in the test environment.
* Tests run against a local MariaDB dev database; production data is never touched.
*/
import { afterEach } from 'vitest'
import { db } from '../src/db/client.js'
import { lists, listItems, listShares } from '../src/db/schema.js'
/**
* Truncate list tables in FK-safe order after each test.
* list_items and list_shares have FK to lists; delete children first.
* Called automatically via afterEach — no per-test setup needed.
*/
afterEach(async () => {
try {
// Delete child rows first to avoid FK constraint violations
await db.delete(listItems)
await db.delete(listShares)
await db.delete(lists)
} catch {
// DB may not be available in pure-unit test runs (no DB_HOST configured).
// Swallow the error — pure-logic tests do not need cleanup.
}
})