#!/bin/bash
# Run canteen test suites with Pixel 9a viewport emulation
# Usage: ./run_tests_pixel9a.sh [suite]
#   Suites: api, frontend, smoke, admin, all (default)

set -e
DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR"

export CANTEEN_DEVICE="pixel_9a"
export CANTEEN_SKIP_AUTH="1"

SUITE="${1:-all}"

run_api() {
  echo "===== Backend API Tests (Pixel 9a context) ====="
  python3 -m pytest tests/test_server.py tests/test_map_api.py tests/test_gap_coverage.py -v --tb=short 2>&1 | tail -20
}

run_frontend() {
  echo "===== Frontend E2E Tests (Pixel 9a viewport) ====="
  python3 -m pytest tests/frontend/ -v --tb=short -m "frontend" 2>&1 | tail -30
}

run_smoke() {
  echo "===== Frontend Smoke Tests (curl-based) ====="
  python3 -m pytest tests/test_frontend_smoke.py -v --tb=short 2>&1 | tail -15
  echo "===== Bash Smoke Tests ====="
  bash smoke_test.sh 2>&1 | tail -20
}

run_admin() {
  echo "===== Admin Server Tests ====="
  cd ~/projects/canteen-admin-server
  python3 -m pytest test_sync_api.py test_cantaloupe_sync.py -v --tb=short 2>&1 | tail -20
  cd "$DIR"
}

case "$SUITE" in
  api)     run_api ;;
  frontend) run_frontend ;;
  smoke)   run_smoke ;;
  admin)   run_admin ;;
  all)
    run_api
    echo ""
    run_frontend
    echo ""
    run_smoke
    echo ""
    run_admin
    ;;
  *)
    echo "Usage: $0 [api|frontend|smoke|admin|all]"
    exit 1
    ;;
esac

echo "===== Done ====="
