name: Test

on: pull_request

jobs:
  lint:
    runs-on: ubuntu-latest
    
    strategy:
      matrix:
        node-version: [22.x]
        
    steps:
    - uses: actions/checkout@v4
    - uses: pnpm/action-setup@v4
      name: Install pnpm
      with:
        run_install: false
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
        registry-url: 'https://registry.npmjs.org'
        cache: 'pnpm'
    - name: Node Install
      run: |
        pnpm install
    - name: Lint
      run: |
        pnpm lint

  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [22.x]

    services:
      mysql:
        image: mysql:8.0.27
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
          MYSQL_DATABASE: 'parcelvoy'
        ports:
          - 3306:3306
        options: >-
          --tmpfs="/var/lib/mysql"
          --health-cmd="mysqladmin ping" 
          --health-interval=10s 
          --health-timeout=5s 
          --health-retries=3

    steps:
    - uses: actions/checkout@v4
    - uses: pnpm/action-setup@v4
      name: Install pnpm
      with:
        run_install: false

    - name: "Setup ClickHouse Server"
      uses: getsentry/action-clickhouse-in-ci@v1.6

    - name: Node 22.x
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
        registry-url: 'https://registry.npmjs.org'
        cache: 'pnpm'

    - name: Install Dependencies
      run: pnpm install

    - name: 'Run Jest Tests'
      run: pnpm test
      env:
        NODE_ENV: test
        APP_SECRET: testing
        DB_CLIENT: mysql2
        DB_DATABASE: parcelvoy
        DB_USERNAME: root
        DB_PORT: 3306
        CLICKHOUSE_URL: http://localhost:8123
        BASE_URL: https://parcelvoy.com
        AUTH_DRIVER: basic
        QUEUE_DRIVER: memory
        STORAGE_DRIVER: s3

  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [22.x]

    steps:
    - uses: actions/checkout@v4
    - uses: pnpm/action-setup@v4
      name: Install pnpm
      with:
        run_install: false
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
        registry-url: 'https://registry.npmjs.org'
        cache: 'pnpm'
    - name: Node Install
      run: |
        pnpm install
    - name: Build
      run: |
        pnpm build
