name: Tests
on:
  workflow_call:
jobs:
  build:
    name: Unit Tests
    runs-on: ubuntu-latest
    timeout-minutes: 15

    steps:
      - uses: actions/checkout@v3
      - uses: ./.github/actions/dangerous-git-checkout

      - name: Setup Node.js 20.x
        uses: actions/setup-node@v3
        with:
          node-version: 20.x

      - name: Install pnpm
        uses: pnpm/action-setup@v4

      - name: Install dependencies
        run: pnpm install --config.platform=linux --config.architecture=x64

      - name: create .env
        run: cp .env.example .env

      - name: Generate Random ENCRYPTION_KEY and fill in .env
        run: |
          ENCRYPTION_KEY=$(openssl rand -hex 32)
          sed -i "s/ENCRYPTION_KEY=.*/ENCRYPTION_KEY=${ENCRYPTION_KEY}/" .env

      - name: Test
        run: pnpm test
