#!/usr/bin/env bash
set -euo pipefail

BASE_URL="${BASE_URL:-http://localhost:8000}"

echo "[1] Health check"
curl -sf "$BASE_URL/health" >/dev/null || { echo "Health check failed"; exit 1; }

echo "[2] API unauthenticated should return 401 JSON"
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/api/rolodex")
if [ "$code" != "401" ]; then
  echo "Expected 401, got $code"
  exit 1
fi

cat << 'EX'
Login via UI at /login to create a session cookie in your browser.
For scripted tests, copy the cookie to cookies.txt and run examples:

curl -b cookies.txt "$BASE_URL/api/rolodex?page=1&page_size=2&sort_by=last_name&sort_dir=asc"
curl -b cookies.txt "$BASE_URL/api/files?page=1&page_size=2&sort_by=open_date&sort_dir=desc"
curl -b cookies.txt "$BASE_URL/api/ledger?page=1&page_size=2&sort_by=transaction_date&sort_dir=desc"
EX

echo "Smoke tests completed."


