feat: add isolated integration test database lifecycle#108
Merged
3m1n3nc3 merged 1 commit intoJul 20, 2026
Merged
Conversation
- Add production database safety guard (tests/helpers/guard.ts) - Add database lifecycle management (tests/helpers/db.ts) - Add test data factories (tests/helpers/factories.ts) - Add transaction isolation helpers (tests/helpers/isolation.ts) - Add global setup for running migrations once per run - Update test setup to integrate guard and per-worker schema - Add integration self-tests for guard, factories, cleanup, isolation - Update vitest config and package.json scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds a complete isolated integration test database lifecycle system to
learnault-api. It provides safe PostgreSQL setup, migrations, factories, cleanup, and parallelism support for integration tests.Related Issue
Closes #70
Changes
🛡️ Database Safety Guard
tests/helpers/guard.tsDATABASE_URLagainst production keywords and host patternsproduction,prod, AWS RDS, Azure, Heroku, Render, Fly, Railway_testdatabase name🗄️ Database Lifecycle Management
tests/helpers/db.tsDROP SCHEMA ... CASCADEprisma db pushonce per run🏭 Test Data Factories
tests/helpers/factories.tsbuildUser/createUser— User factory with unique email/usernamebuildModule/createModule— Module factorybuildCompletion/createCompletion— Completion factorycreateUserWithModule— Combined factory for common test setup🔄 Test Isolation
withIsolation— Wraps test logic in a Prisma transaction for automatic rollbackcreateIsolatedTest— Convenience wrapper for isolated test functions⚙️ Configuration & Setup
tests/globalSetup.ts— Runs migrations once before all test workerstests/setup.ts— Integrates guard validation + per-worker schema creationvitest.config.js— AddedglobalSetupconfigurationpackage.json— Addedtest:integrationandtest:integration:watchscripts🧪 Self-Tests
tests/integration/guard.test.ts— 4 tests verifying production URL rejectiontests/integration/factories.test.ts— 7 tests verifying factory outputtests/integration/cleanup.test.ts— 5 tests verifying schema/URL utilitiestests/integration/isolation.test.ts— 5 tests (3 DB-dependent skipped gracefully)Verification Results