2.1 KiB
2.1 KiB
Test Database Setup - Quick Reference
✅ Setup Complete
The test database configuration files have been created:
.env.test- Test environment variables (create/edit with your credentials).env.test.example- Example configurationjest.config.js- Jest configuration with environment loadingtests/load-env.ts- Environment loader for tests
🚀 Quick Start
Step 1: Create Test Database
createdb dbis_core_test
Or with Docker:
docker run --name dbis-postgres-test \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_USER=postgres \
-p 5432:5432 \
-d postgres:15
sleep 5
docker exec -i dbis-postgres-test psql -U postgres -c "CREATE DATABASE dbis_core_test;"
Step 2: Update .env.test
Edit .env.test with your PostgreSQL credentials:
TEST_DATABASE_URL=postgresql://USERNAME:PASSWORD@localhost:5432/dbis_core_test
Step 3: Run Migrations
export TEST_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/dbis_core_test"
DATABASE_URL=$TEST_DATABASE_URL npm run migrate
Step 4: Run Tests
npm test
📝 Files Created
.env.test- Test environment configuration (you may need to update credentials)jest.config.js- Jest configuration that loads .env.testtests/load-env.ts- Loads environment variables before testsscripts/setup-test-db.sh- Automated setup script (requires PostgreSQL running)scripts/quick-test-setup.sh- Quick reference scriptREADME_TEST_DATABASE.md- Detailed setup guide
🔍 Verify Setup
# Check database exists
psql -U postgres -l | grep dbis_core_test
# Check tables
psql -U postgres -d dbis_core_test -c "\dt"
# Run a test
npm test -- tests/validation/payment-validation.test.ts
⚠️ Notes
- The
.env.testfile uses default PostgreSQL credentials (postgres/postgres) - Update
.env.testif your PostgreSQL uses different credentials - The test database will be truncated between test runs
- Never use your production database as the test database
Next: Run npm test to execute the full test suite!