name: Test Codebase
on:
  push:
    branches: [ main, develop ]

  pull_request:
    branches: [ main, develop ]

permissions:
  contents: read

jobs:
  run_tests:
    name: Test Codebase
    runs-on: ubuntu-latest
    steps:
      - name: Checkout "${{ github.repository }}"
        uses: actions/checkout@v4

      - name: Set up Node v21
        uses: actions/setup-node@v4
        with:
          node-version: '21.x'

      - name: Install dependencies
        run:  |
          cd CoVAR-app && npm ci

      - name: Test Codebase
        run:  |
          cd CoVAR-app && npm run test


      - name: Jest Coverage Comment
        id: coverageComment
        uses: MishaKav/jest-coverage-comment@main
        with:
          hide-comment: true
          coverage-summary-path: ./CoVAR-app/coverage/coverage-summary.json

      - name: Check the output coverage
        run: |
          echo "Coverage Percentage - ${{ steps.coverageComment.outputs.coverage }}"
          echo "Coverage Color - ${{ steps.coverageComment.outputs.color }}"
          echo "Summary HTML - ${{ steps.coverageComment.outputs.summaryHtml }}"