Files
dbis_core-lite/docs/deployment/test-database-setup.md
2026-02-09 21:51:45 -08:00

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 configuration
  • jest.config.js - Jest configuration with environment loading
  • tests/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

  1. .env.test - Test environment configuration (you may need to update credentials)
  2. jest.config.js - Jest configuration that loads .env.test
  3. tests/load-env.ts - Loads environment variables before tests
  4. scripts/setup-test-db.sh - Automated setup script (requires PostgreSQL running)
  5. scripts/quick-test-setup.sh - Quick reference script
  6. README_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.test file uses default PostgreSQL credentials (postgres/postgres)
  • Update .env.test if 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!