name: 'Integration Tests'

env:
  INGITHUB: true

on:
  push:
    paths-ignore:
      - 'README.md'
      - 'LICENSE'
      - 'SECURITY.md'
  pull_request:

jobs:
  integration:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [20.x, 22.x, 24.x]

    name: 'Integration Node v${{ matrix.node-version }}'

    steps:
      - uses: actions/checkout@v3

      - name: Install LDAP tools
        run: sudo apt-get install -y ldap-utils

      - name: Start containers
        run: docker compose -f "docker-compose.yml" up -d

      - name: Wait for LDAP server to become available
        uses: nick-fields/retry@v2
        with:
          timeout_minutes: 5
          max_attempts: 10
          polling_interval_seconds: 3
          command: |
            ldapsearch -LLL -o 'ldif-wrap=no' \
              -H ldap://localhost:1389 \
              -D 'cn=read-only-admin,dc=example,dc=com' \
              -w password \
              -b 'cn=einstein,ou=users,dc=example,dc=com' DN

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: npm run test

      - name: Stop containers
        if: always()
        run: docker compose -f "docker-compose.yml" down
