mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
The repo had no automated tests. Every change was verified by hand. Adds four layers, 2023 tests in total, runnable with one command: - 1191 unit tests over the pure logic in lib/, including the full computeProjectAccess permission matrix and the billing gate - 167 component and hook tests in jsdom, covering the hooks that hold real logic rather than presentational wrappers - 647 API integration tests against a real Postgres, with only auth() mocked, including a data-driven sweep asserting that none of the 60 route modules answers 2xx to an unauthenticated caller - 18 Playwright specs driving a real browser against a real build Infrastructure: vitest.config.ts with three projects, a disposable Postgres and MinIO in docker-compose.test.yml, factories and helpers under tests/, scripts/test.sh as the single entry point, a pre-push hook running bun run verify, and CI split into check, test and e2e jobs. The test database is built with prisma db push plus a replay of the hand-written SQL, because prisma migrate deploy cannot build this schema from empty: the migration history has no captured baseline. This mirrors what scripts/docker-db-bootstrap.ts already does in production, and tests/setup/db-global.ts carries a drift guard so a new migration fails the run until someone reviews it. Production code is unchanged apart from one pure-function extraction out of use-video-player.ts, which was too large to test in jsdom. Several tests pin behaviour that looks wrong, each marked KNOWN BUG in place. TESTING.md section 12 records where the plan turned out to be wrong, and AGENTS.md now states which layer a change needs a test in.
23 lines
821 B
TypeScript
23 lines
821 B
TypeScript
/**
|
|
* Builds the test database schema outside of Vitest.
|
|
*
|
|
* The `api` Vitest project gets this for free through its globalSetup, but the
|
|
* end-to-end suite runs the real app against the same database and needs the
|
|
* schema in place before the server starts. Both paths therefore call the same
|
|
* setup function, so there is exactly one description of how a test database is
|
|
* built (including why it uses `prisma db push` rather than `migrate deploy`,
|
|
* which is documented at the top of tests/setup/db-global.ts).
|
|
*
|
|
* Usage: bun run test:db:bootstrap
|
|
*/
|
|
import { setup } from '../tests/setup/db-global';
|
|
|
|
setup()
|
|
.then(() => {
|
|
console.log('Test database schema is ready');
|
|
})
|
|
.catch((error: unknown) => {
|
|
console.error(error instanceof Error ? error.message : error);
|
|
process.exit(1);
|
|
});
|