#!/bin/bash
# Test FastAPI landing endpoint and print status so it's visible.
# Usage: bash scripts/test_landing.sh   (or from repo root on server)

set -e
URL="${1:-http://127.0.0.1:8001/landing}"
echo "Testing: $URL"
code=$(curl -sS -o /tmp/landing_test.json -w "%{http_code}" --connect-timeout 5 "$URL")
echo "HTTP status: $code"
if [ -s /tmp/landing_test.json ]; then
  echo "Body (first 200 chars): $(head -c 200 /tmp/landing_test.json)"
else
  echo "Body: (empty)"
fi
if [ "$code" = "200" ]; then
  echo "OK – landing API is working."
else
  echo "If 404/500: ensure landing tables exist: mysql -u USER -p DB < scripts/sql/landing_content_tables.sql"
  echo "Logs: journalctl -u fastapi -n 30 --no-pager"
fi
