-
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/44 docker setup #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
- Modified .env.test to include test database configuration and updated server ports. - Updated .gitignore to ensure .env.test is not ignored. - Enhanced package.json with additional scripts for building, formatting, linting, and seeding test data. This commit improves the setup for testing and development workflows.
- Changed permissions of `verify-test-db-setup.sh` to make it executable. - Modified the SQL command in `verify-test-db-setup.sh` to check for the pgcrypto extension using a more precise output format. - Updated the insert statement in `verify-test-db-setup.sh` to reflect the correct column names in the contacts table. - Ensured the pgcrypto extension is created in `seed.sql` for UUID generation. These changes enhance the accuracy and reliability of the test database setup process.
Signed-off-by: Neel Mokaria <145509611+nmokaria27@users.noreply.github.com>
verify-test-db-setup.sh
Outdated
| echo -e " (Runs all 80+ tests including Docker interaction)" | ||
| echo -e " 2. Run: ${YELLOW}docker compose up -d${NC}" | ||
| echo -e " (Start your test database)" | ||
| echo -e " 3. Run: ${YELLOW}npm run test${NC}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know in the issue description I used npm run test, but npm run test would actually run the tests that connect to Supabase, and so currently even with docker container running, the supabase itself is getting changed. Can we create a new test command that would specifically run the tests but make sure it uses the local test database rather than the Supabase database itself? Basically right now, it doesn't seem to be using .env.test information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted all data in current database in supabase so you can easily check if any data is getting created in there when it shouldn't anymore
soramicha
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed my .env NODE_ENV to test, but when I run npm run test:local, the database in Supabase itself is changed! Also please update the PR itself if there are any changes in commands, instructions, etc.
- Added npm script `test:docker` that runs test:local for Docker environment testing - Configured dotenv to override existing env vars when NODE_ENV=test to ensure test database configuration takes precedence - Updated verify-test-db-setup.sh documentation to reference new test:docker command
Here is the updated PR description with the new commands and configuration changes included.
Docker Setup and Test Database #49
Closes #49
Overview
This PR implements a comprehensive Docker-based test database setup to enable isolated testing for the volunteer management backend. The implementation provides a complete testing environment that runs independently from the production database, ensuring test isolation and repeatability.
Key Changes:
Created Docker container configuration for PostgreSQL test database
Implemented complete database schema with 6 enums and 15 tables
Added test environment configuration and application integration
Implemented strict environment variable enforcement to prevent accidental production connections
Created comprehensive testing scripts with 77 automated tests
Established repeatable test cycles for CI/CD integration
Testing
Automated Testing:
Created verify-test-db-setup.sh with 77 comprehensive tests across 14 phases
Tests cover file structure, SQL schema validation, Docker operations, database connectivity, data isolation, and full lifecycle management
All tests pass with 100% success rate
Manual Testing:
Verified complete test cycle:
docker compose up -d→npm run test:docker→docker compose down -vTested manual reseeding with
npm run seed:testValidated data isolation between test runs
Confirmed schema recreation after container restart
Verified Supabase/Production data remains untouched during test execution
Test Coverage:
File existence and configuration validation
SQL schema integrity (6 enums, 15 tables, foreign keys)
Docker container lifecycle management
Database connectivity and operations
Application integration with test environment
Port configuration and network accessibility
Screenshots / Screencasts
Run
./verify-test-db-setup.sh --fullto test the docker & seed.sql related tests.Test Script Execution:
$ ./verify-test-db-setup.sh --full ======================================== FULL DATABASE ROBUSTNESS TEST (80+ tests across 14 phases) ======================================== Total Tests Run: 77 Tests Passed: 77 Tests Failed: 0 Success Rate: 100% ✅ All checks passed!Database Schema Validation:
Checklist
Notes
Files Created:
1. docker-compose.yml - Docker container configuration
- PostgreSQL 16 Alpine image
- Port mapping (5433:5432) to avoid conflicts
- Volume mounting for auto-seeding
- Health checks and networking
2.
db-init/seed.sql- Complete database schema (258 lines)- 6 enum types (action_type, level_type, status_type, volunteer_status, volunteer_type, project_type)
- 15 tables in correct dependency order
- All foreign key constraints and unique constraints
- Idempotent reseeding (DROP/CREATE schema)
3. .env.test - Test environment configuration
- DATABASE_URL pointing to localhost:5433
- NODE_ENV=test
- Server port configurations
4. verify-test-db-setup.sh - Comprehensive testing script (393 lines)
- Quick mode (7 tests, 1 second)
- Full mode (77 tests, 60 seconds)
- 14 test phases covering all aspects
- Color-coded output and detailed reporting
Files Modified:
1. src/config/server.ts - Application configuration
- Added conditional loading of .env.test when NODE_ENV=test
- Added
override: trueto forcibly prioritize test variables over shell environment variables2. package.json - NPM scripts
- Added
seed:testscript for manual database reseeding- Added
test:dockerscript to explicitly run tests against local container- Command:
docker compose exec -T test-db psql -U postgres -d test_db -f /docker-entrypoint-initdb.d/seed.sqlHow to Use:
Basic Workflow:
Verification:
Manual Reseeding:
# Reseed database without restarting container npm run seed:testComplete Test Cycle:
# Full cycle test docker compose down -v docker compose up -d sleep 10 npm run test:dockerKey Benefits:
Technical Details: