name: django-unit-tests

on:
  push:
    branches: [ main ]
  pull_request:
  workflow_dispatch:

defaults:
  run:
    working-directory: ./django/aiservice

jobs:
  unit-tests:

    runs-on: ubuntu-latest

    env:
      SECRET_KEY: ${{ secrets.SECRET_KEY }}
      DATABASE_URL: ${{ secrets.DATABASE_URL }}
      OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Set up Python 3.12.2
        uses: actions/setup-python@v5
        with:
          python-version: "3.12.2"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install poetry
          poetry install
      - name: Django Unit tests
        run: |
          poetry run pytest
