version: '3.8'

services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: rwadurian_planting_test
    ports:
      - "5433:5432"
    volumes:
      - postgres_test_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  test:
    build:
      context: .
      dockerfile: Dockerfile.test
    depends_on:
      db:
        condition: service_healthy
    environment:
      NODE_ENV: test
      DATABASE_URL: postgresql://postgres:postgres@db:5432/rwadurian_planting_test?schema=public
      JWT_SECRET: test-jwt-secret
      WALLET_SERVICE_URL: http://localhost:3002
      IDENTITY_SERVICE_URL: http://localhost:3001
      REFERRAL_SERVICE_URL: http://localhost:3004
    volumes:
      - ./src:/app/src
      - ./test:/app/test
      - ./prisma:/app/prisma

volumes:
  postgres_test_data:
