name: transaction-exclusion-api-testing

on:
  workflow_call:
    secrets:
      DOCKERHUB_USERNAME:
        required: false
      DOCKERHUB_TOKEN:
        required: false
  workflow_dispatch:
    inputs:
      coverage:
        description: To generate test report
        required: false
        type: boolean
        default: false

concurrency:
  group: transaction-exclusion-api-testing-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
  run-tests:
    env:
      DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
      DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
    # ~1.5 mins saved vs small
    runs-on: gha-runner-scale-set-ubuntu-22.04-amd64-med
    name: Transaction exclusion api tests
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 21
      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@8379f6a1328ee0e06e2bb424dadb7b159856a326 # 4.4.0
      - name: Run tests with coverage
        if: ${{ inputs.coverage }}
        run: |
          ./gradlew transaction-exclusion-api:app:buildNeeded jacocoRootReport
      - name: Run tests without coverage
        if: ${{ !inputs.coverage }}
        run: |
          ./gradlew transaction-exclusion-api:app:buildNeeded
      - name: Login to Docker Hub
        if: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }}
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Run integration tests
        run: |
          ./gradlew transaction-exclusion-api:app:integrationTestAllNeeded
