# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js Tests

permissions:
  contents: read

on:
  pull_request:
    branches: [ development, master, main ]

jobs:
  unit-tests:
    name: Unit Tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [ 16.x, 18.x, 20.x, 22.x]
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
      - name: Install dependencies
        run: npm ci
      - name: Run unit tests
        run: npm test -- --testPathIgnorePatterns=e2e.test.js

  e2e-tests:
    name: End-to-End Tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [ 16.x, 18.x, 20.x, 22.x]
    env:
      LOGZIO_API_TOKEN: ${{ secrets.LOGZIO_API_TOKEN }}
      LOGZIO_LOGS_TOKEN: ${{ secrets.LOGZIO_LOGS_TOKEN }}
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
      - name: Install dependencies
        run: npm ci
      - name: Run E2E tests
        run: npm run test:e2e
