Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions dev_env/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ services:
# Slack failure simulation (for testing error handling)
# Set SIMULATE_SLACK_FAILURE=true to test Slack webhook failure scenarios
- SIMULATE_SLACK_FAILURE=${SIMULATE_SLACK_FAILURE:-false}
# Rate limiting is disabled by default in test mode (USE_MOCK_SERVICES=true)
# To run rate limiting tests, rebuild with TEST_RATE_LIMITING=true:
# TEST_RATE_LIMITING=true docker compose ... up -d --build backend
# Rate limiting configuration
# Set TEST_RATE_LIMITING=true to enable rate limiting in test mode
# Use ci:env:full and ci:test:full npm scripts to run with rate limiting enabled
- TEST_RATE_LIMITING=${TEST_RATE_LIMITING:-false}
# Rate limit config (only applies when TEST_RATE_LIMITING=true):
- RATE_LIMIT_REGISTRATION_WINDOW_MS=2000
- RATE_LIMIT_REGISTRATION_MAX=3
- RATE_LIMIT_REGISTRATION_MAX=5
- RATE_LIMIT_REQUEST_WINDOW_MS=2000
- RATE_LIMIT_REQUEST_MAX=3
- RATE_LIMIT_REQUEST_MAX=20
ports:
- '${CI_PORT:-8081}:8080'

Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
"db:start": "docker compose -f dev_env/docker-compose.yml --env-file .env --profile dev up -d; docker attach wxyc-db-init",
"db:stop": "docker compose -f dev_env/docker-compose.yml --env-file .env --profile dev down db -v --remove-orphans",
"ci:build": "npm run docker:build --workspace=apps/**",
"ci:env": "sh -c 'COMPOSE=\"docker compose -f dev_env/docker-compose.yml --env-file .env --profile ci\" && $COMPOSE up -d ci-db && $COMPOSE up ci-db-init && $COMPOSE up -d ${BUILD_ENABLED:+--build} auth backend'",
"ci:test": "DB_PORT=${CI_DB_PORT:-5433} PORT=${CI_PORT:-8081} BETTER_AUTH_URL=${CI_BETTER_AUTH_URL:-http://localhost:8083/auth} dotenvx run -f .env -- jest --config jest.config.json --runInBand --coverage",
"ci:env": "./scripts/ci-env.sh",
"ci:env:full": "./scripts/ci-env.sh --full",
"ci:test": "./scripts/ci-test.sh",
"ci:test:full": "./scripts/ci-test.sh --full",
"ci:test:parallel": "DB_PORT=${CI_DB_PORT:-5433} PORT=${CI_PORT:-8081} BETTER_AUTH_URL=${CI_BETTER_AUTH_URL:-http://localhost:8083/auth} dotenvx run -f .env -- jest --config jest.parallel.config.json --coverage",
"ci:clean": "docker compose -f dev_env/docker-compose.yml --env-file .env --profile ci down -v",
"ci:testmock": "npm run ci:env && npm run ci:test && npm run ci:clean",
"ci:testmock:full": "npm run ci:env:full && npm run ci:test:full && npm run ci:clean",
"e2e:env": "npm run docker:build --workspace=apps/** && docker compose -f dev_env/docker-compose.yml --env-file .env --profile e2e up -d e2e-db && docker compose -f dev_env/docker-compose.yml --env-file .env --profile e2e up e2e-db-init && docker compose -f dev_env/docker-compose.yml --env-file .env --profile e2e up -d e2e-auth e2e-backend",
"e2e:setup-users": "E2E_DB_PORT=${E2E_DB_PORT:-5434} DB_PORT=${E2E_DB_PORT:-5434} npm run setup:e2e-users",
"e2e:clean": "docker compose -f dev_env/docker-compose.yml --env-file .env --profile e2e down -v",
Expand Down
61 changes: 61 additions & 0 deletions scripts/ci-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
# CI Environment Setup Script
# Usage: ./scripts/ci-env.sh [--full]
#
# Options:
# --full Enable rate limiting and create default admin user for full test suite

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

# Parse arguments
FULL_MODE=false
for arg in "$@"; do
case $arg in
--full)
FULL_MODE=true
shift
;;
esac
done

# Build the Docker images
npm run ci:build

# Set up compose command with environment
COMPOSE_CMD="docker compose -f $PROJECT_ROOT/dev_env/docker-compose.yml --env-file $PROJECT_ROOT/.env --profile ci"

if [ "$FULL_MODE" = true ]; then
echo "Starting CI environment with full test configuration..."
echo " - Rate limiting: ENABLED"

# Export rate limiting for Docker Compose
export TEST_RATE_LIMITING=true

# Only enable default admin user if credentials are configured
# (needed for admin ban tests)
if [ -n "$DEFAULT_USER_EMAIL" ] && [ -n "$DEFAULT_USER_USERNAME" ] && [ -n "$DEFAULT_USER_PASSWORD" ]; then
echo " - Default admin user: ENABLED"
export CREATE_DEFAULT_USER=TRUE
else
echo " - Default admin user: DISABLED (credentials not configured)"
echo " To enable, set DEFAULT_USER_EMAIL, DEFAULT_USER_USERNAME, DEFAULT_USER_PASSWORD,"
echo " DEFAULT_USER_DJ_NAME, DEFAULT_USER_REAL_NAME, DEFAULT_ORG_SLUG, DEFAULT_ORG_NAME in .env"
fi
else
echo "Starting CI environment with standard configuration..."
fi

# Start database
$COMPOSE_CMD up -d ci-db

# Run database initialization
$COMPOSE_CMD up ci-db-init

# Start auth and backend services
# Environment variables are already exported above, Docker Compose will inherit them
$COMPOSE_CMD up -d auth backend

echo "CI environment is starting. Use 'npm run ci:test' to run tests."
48 changes: 48 additions & 0 deletions scripts/ci-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# CI Test Runner Script
# Usage: ./scripts/ci-test.sh [--full]
#
# Options:
# --full Run all tests including rate limiting and admin ban tests

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

# Parse arguments
FULL_MODE=false
for arg in "$@"; do
case $arg in
--full)
FULL_MODE=true
shift
;;
esac
done

# Base environment variables
export DB_HOST=localhost
export DB_PORT=${CI_DB_PORT:-5433}
export PORT=${CI_PORT:-8081}
export BETTER_AUTH_URL=${CI_BETTER_AUTH_URL:-http://localhost:8083/auth}

if [ "$FULL_MODE" = true ]; then
echo "Running full test suite..."
echo " - Rate limiting tests: ENABLED"
echo " - Admin ban tests: DISABLED (requires AUTH_USERNAME/AUTH_PASSWORD - see GitHub issue)"
export TEST_RATE_LIMITING=true
# Pass rate limit config to test runner (must match docker-compose.yml values)
export RATE_LIMIT_REGISTRATION_WINDOW_MS=2000
export RATE_LIMIT_REGISTRATION_MAX=5
export RATE_LIMIT_REQUEST_WINDOW_MS=2000
export RATE_LIMIT_REQUEST_MAX=20
# TEST_ADMIN_BAN disabled until admin credentials are configured
# export TEST_ADMIN_BAN=true
else
echo "Running standard test suite..."
fi

# Run tests with dotenvx to load .env file
cd "$PROJECT_ROOT"
dotenvx run -f .env -- jest --config jest.config.json --runInBand --coverage