name: 'Test: Workflows'

on:
  workflow_call:
    inputs:
      git_ref:
        description: 'The Git ref (branch, tag, or SHA) to checkout and test.'
        required: true
        type: string
      compare_schemas:
        description: 'Set to "true" to enable schema comparison during tests.'
        required: false
        default: 'false'
        type: string
    secrets:
      ENCRYPTION_KEY:
        description: 'Encryption key for n8n operations.'
        required: true
      CURRENTS_RECORD_KEY:
        description: 'Currents record key for test reporting. Empty on fork PRs.'
        required: false

env:
  NODE_OPTIONS: --max-old-space-size=3072

jobs:
  run_workflow_tests:
    name: Run Workflow Tests with Snapshots
    runs-on: blacksmith-2vcpu-ubuntu-2204
    steps:
      - name: Checkout repository
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          ref: ${{ inputs.git_ref }}

      - name: Set up Environment
        uses: ./.github/actions/setup-nodejs

      - name: Set up Workflow Tests
        run: pnpm --filter=n8n-playwright test:workflows:setup
        env:
          N8N_ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }}

      - name: Run Workflow Tests
        run: pnpm --filter=n8n-playwright test:workflows --workers 4
        env:
          CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
          CURRENTS_PROJECT_ID: 'mpLFH9'

      - name: Run Workflow Schema Tests
        if: ${{ inputs.compare_schemas == 'true' }}
        run: pnpm --filter=n8n-playwright test:workflows:schema
        env:
          CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
          CURRENTS_PROJECT_ID: 'mpLFH9'
