name: Test Code

on: [push, workflow_call, pull_request]

jobs:
  test-backend:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.x"
      - name: Install dependencies
        run: |
          cd backend
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: Test with pytest
        run: |
          cd backend
          pip install pytest pytest-cov
          pytest

  test-frontend:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6
      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "20.x"
      - name: Install dependencies
        run: |
          cd frontend
          npm ci
      - name: Test with NPM
        run: |
          cd frontend
          npm test -- run --exclude "**/*.live.test.ts"
