name: Unit Tests

on:
  pull_request:
    branches:
      - main
  workflow_dispatch:
    inputs:
      branch:
        description: 'Branch name'
        required: true
        default: 'main'

jobs:
  unit-tests:
    name: Run unit tests
    runs-on: ubuntu-latest
    steps:
    - name: Check out code
      uses: actions/checkout@v2

    - name: Set up Go
      uses: actions/setup-go@v2
      with:
        go-version: '^1.22'

    - name: Yarn install
      uses: borales/actions-yarn@v4
      with:
        cmd: install
        dir: 'frontend'

    - name: Yarn build
      uses: borales/actions-yarn@v4
      with:
        cmd: build
        dir: 'frontend'

    - name: Install dependencies
      run: |
        echo "Installing dependencies ..."
        go mod tidy

    - name: Run unit tests
      run: |
        echo "Running unit tests ..."
        go test -v -cover ./...
