name: E2E Tests
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
jobs:
  build-and-test:
    timeout-minutes: 20
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: lts/*
          cache: 'npm'
          cache-dependency-path: frontend/package-lock.json
      
      - name: Build Docker Image
        run: docker build -t stonith404/pocket-id .
      - name: Run Docker Container
        run: docker run -d --name pocket-id -p 80:80 --env-file .env.test stonith404/pocket-id

      - name: Install frontend dependencies
        working-directory: ./frontend
        run: npm ci

      - name: Install Playwright Browsers
        working-directory: ./frontend
        run: npx playwright install --with-deps chromium

      - name: Run Playwright tests
        working-directory: ./frontend
        run: npx playwright test

      - name: Get container logs
        if: always()
        run: docker logs pocket-id

      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: playwright-report
          path: frontend/tests/.output
          retention-days: 15
