name: Backend Unit Tests
on:
  push:
  pull_request:
  workflow_dispatch:

jobs:
  unit-test:
    name: Backend Unit Tests
    runs-on: ${{ vars.LABEL_WORKER_SELFHOSTED }}
    steps:
      - name: Setup Node.js
        uses: actions/setup-node@v5
        with:
          node-version: '22.13'
      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 10.18.3
      - name: Checkout OpenVidu Meet
        uses: actions/checkout@v4

      - name: Install dependencies
        run: ./meet.sh install

      - name: Build typings
        run: ./meet.sh build-typings --skip-install

      - name: Run tests
        run: ./meet.sh test-unit-backend --skip-install
        env:
          JEST_JUNIT_OUTPUT_DIR: './backend/reports/'

      - name: Publish Test Report
        uses: mikepenz/action-junit-report@v4
        if: always()
        with:
          report_paths: '**/reports/junit.xml'
          fail_on_failure: true
          require_tests: true

      - name: Clean up
        if: always()
        uses: OpenVidu/actions/cleanup@main
