# System test profile — runs full stack with seed data + Playwright
# Usage: docker compose -f docker-compose.test.yml up --abort-on-container-exit
include:
  - docker-compose.yml

services:
  # Override db to include seed data
  db:
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./scripts/seed/init.sql:/docker-entrypoint-initdb.d/99-seed.sql:ro

  # Seed container: waits for backend health, then validates readiness
  seed:
    image: curlimages/curl:latest
    container_name: cannamanage-seed
    depends_on:
      backend:
        condition: service_healthy
    entrypoint: /bin/sh
    command: ["-c", "/seed/seed.sh"]
    volumes:
      - ./scripts/seed:/seed:ro

  # Playwright system tests
  playwright:
    image: mcr.microsoft.com/playwright:v1.52.0-noble
    container_name: cannamanage-playwright
    working_dir: /app
    depends_on:
      seed:
        condition: service_completed_successfully
      frontend:
        condition: service_started
    environment:
      BASE_URL: http://frontend:3000
      CI: "true"
    volumes:
      - ./cannamanage-frontend:/app
    command: >
      sh -c "
        echo 'Waiting for frontend to be ready...' &&
        timeout 60 sh -c 'until wget -q -O /dev/null http://frontend:3000 2>/dev/null; do sleep 2; done' &&
        echo 'Frontend ready — running system tests...' &&
        npx playwright test e2e/system-test.spec.ts --reporter=list
      "
