name: App Tests

on: [push, pull_request, workflow_dispatch]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: ["3.11"]

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install Dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements-dev.txt

      - name: Ruff
        run: |
          ruff check src

      - name: Run Tests
        env:
          SECRET: ${{ secrets.SECRET }}
          TMDB_API: ${{ secrets.TMDB_API }}
          MAL_API: ${{ secrets.MAL_API }}
          IGDB_ID: ${{ secrets.IGDB_ID }}
          IGDB_SECRET: ${{ secrets.IGDB_SECRET }}
        run: |
          coverage run --parallel-mode src/manage.py test app
          coverage run --parallel-mode src/manage.py test users
          coverage run --parallel-mode src/manage.py test integrations
          coverage run --parallel-mode src/manage.py test lists

      - name: Build Coverage Report
        run: |
          coverage combine
          coverage report
          coverage xml

      - name: Upload coverage reports to Codecov with GitHub Action
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
