138 lines
4.7 KiB
YAML
Executable file
138 lines
4.7 KiB
YAML
Executable file
# =============================================================================
|
|
# Merchant API E2E Testing Environment
|
|
# =============================================================================
|
|
#
|
|
# Self-contained test environment with PostgreSQL database, seed data,
|
|
# and test runner. Everything runs in Docker, tests execute, then cleanup.
|
|
#
|
|
# Usage:
|
|
# pnpm test:e2e:docker # Build, test, cleanup (one command)
|
|
# pnpm test:e2e:docker:down # Manual cleanup
|
|
#
|
|
# Or directly:
|
|
# docker compose -f docker-compose.e2e.yml up --build --abort-on-container-exit
|
|
# docker compose -f docker-compose.e2e.yml down -v
|
|
#
|
|
# =============================================================================
|
|
|
|
services:
|
|
# ===========================================================================
|
|
# DATABASE: PostgreSQL with merchant schema and seed data
|
|
# ===========================================================================
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
environment:
|
|
POSTGRES_USER: merchant_e2e
|
|
POSTGRES_PASSWORD: merchant_e2e_test
|
|
POSTGRES_DB: merchant_e2e
|
|
volumes:
|
|
# Seed data loaded on startup (alphabetical order)
|
|
- ./test/fixtures/seed.sql:/docker-entrypoint-initdb.d/01-seed.sql:ro
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U merchant_e2e -d merchant_e2e"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
networks:
|
|
- e2e-network
|
|
# No persistent volume - data is ephemeral for testing
|
|
|
|
# ===========================================================================
|
|
# REDIS: BullMQ queue for domain events
|
|
# ===========================================================================
|
|
redis:
|
|
image: redis:7-alpine
|
|
expose:
|
|
- "6379"
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
networks:
|
|
- e2e-network
|
|
# No persistent volume - ephemeral for testing
|
|
|
|
# ===========================================================================
|
|
# MERCHANT API: NestJS Backend
|
|
# ===========================================================================
|
|
api:
|
|
build:
|
|
context: ../../../.. # Build from workspace root (4 levels up)
|
|
dockerfile: codebase/features/merchant/backend-api/Dockerfile.e2e
|
|
args:
|
|
NPM_REGISTRY: ${NPM_REGISTRY:-http://npm.black.lan/}
|
|
# VPN host entry for Forgejo registry (pnpm install from forge.black.lan)
|
|
extra_hosts:
|
|
- "npm.black.lan:10.0.0.11"
|
|
- "forge.black.lan:10.0.0.11"
|
|
# Runtime extra_hosts (for container networking)
|
|
extra_hosts:
|
|
- "npm.black.lan:10.0.0.11"
|
|
- "forge.black.lan:10.0.0.11"
|
|
environment:
|
|
NODE_ENV: test
|
|
PORT: 3020
|
|
# Database connection
|
|
DATABASE_POSTGRES_HOST: postgres
|
|
DATABASE_POSTGRES_USER: merchant_e2e
|
|
DATABASE_POSTGRES_PASSWORD: merchant_e2e_test
|
|
DATABASE_POSTGRES_NAME: merchant_e2e
|
|
# Disable TypeORM auto-sync in tests (we use seed.sql)
|
|
DATABASE_SYNCHRONIZE: "false"
|
|
# Disable auth for E2E tests
|
|
DISABLE_AUTH: "true"
|
|
# Redis connection for BullMQ domain events
|
|
REDIS_HOST: redis
|
|
REDIS_PORT: 6379
|
|
expose:
|
|
- "3020"
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-q", "--spider", "http://localhost:3020/health"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 15
|
|
networks:
|
|
- e2e-network
|
|
|
|
# ===========================================================================
|
|
# E2E TESTS: Jest/Supertest test runner
|
|
# ===========================================================================
|
|
e2e-tests:
|
|
build:
|
|
context: ../../../.. # Build from workspace root (4 levels up)
|
|
dockerfile: codebase/features/merchant/backend-api/Dockerfile.e2e
|
|
args:
|
|
NPM_REGISTRY: ${NPM_REGISTRY:-http://npm.black.lan/}
|
|
extra_hosts:
|
|
- "npm.black.lan:10.0.0.11"
|
|
- "forge.black.lan:10.0.0.11"
|
|
extra_hosts:
|
|
- "npm.black.lan:10.0.0.11"
|
|
- "forge.black.lan:10.0.0.11"
|
|
environment:
|
|
CI: "true"
|
|
NODE_ENV: test
|
|
# Connect tests directly to postgres for database assertions
|
|
DATABASE_URL: postgresql://merchant_e2e:merchant_e2e_test@postgres:5432/merchant_e2e
|
|
# API base URL for supertest requests
|
|
API_BASE_URL: http://api:3020
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
volumes:
|
|
# Mount test results directory for artifacts
|
|
- ./test/results:/app/features/merchant/backend-api/test/results
|
|
networks:
|
|
- e2e-network
|
|
# Run E2E tests and exit
|
|
command: pnpm test:e2e
|
|
|
|
networks:
|
|
e2e-network:
|
|
driver: bridge
|