name: Test
run-name: ${{ gitea.actor }}
on: [workflow_call]

jobs:
  build:
    runs-on: ubuntu-latest
    services:
      redis:
        image: redis:7.4.1-alpine
        # command: redis-server --save 20 1 --loglevel warning --requirepass development
        ports:
          - 6379:6379

      postgres:
        image: postgres:17-alpine

        env:
          POSTGRES_PASSWORD: postgres
          POSTGRES_USER: postgres
          POSTGRES_DB: postgres

        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5432:5432
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Use Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: 1.1.29

      - name: Install dependencies
        run: bun install

      - name: Push Database - Test
        run: bun db:push:force
        env:
          POSTGRES_URL: postgres://postgres:postgres@postgres:5432/postgres
      
      - name: Test API
        run: bun test:api
        env:
          NODE_ENV: test
          POSTGRES_URL: postgres://postgres:postgres@postgres:5432/postgres
          REDIS_URL: redis://redis:6379
          REDIS_PASSWORD: development