#!/bin/bash # API smoke tests for edu.senex.de BASE="${1:-https://edu.senex.de}" COOKIE="/tmp/edu-test-cookies.txt" PASS=0; FAIL=0 test_ep() { local desc="$1" method="$2" path="$3" data="$4" expect="$5" local code if [ "$method" = "POST" ]; then code=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "Content-Type: application/json" -d "$data" -b "$COOKIE" -c "$COOKIE" "${BASE}${path}") elif [ "$method" = "DELETE" ]; then code=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE -b "$COOKIE" -c "$COOKIE" "${BASE}${path}") else code=$(curl -s -o /dev/null -w "%{http_code}" -b "$COOKIE" "${BASE}${path}") fi if [ "$code" = "$expect" ]; then echo " PASS: $desc ($code)"; ((PASS++)) else echo " FAIL: $desc (expected $expect, got $code)"; ((FAIL++)); fi } echo "=== edu.senex.de API Tests ===" echo "Base: $BASE" echo "--- Auth ---" test_ep "me without auth" GET "/api/me" "" "401" test_ep "login wrong pass" POST "/api/login" '{"username":"harry","password":"wrong"}' "401" test_ep "login" POST "/api/login" '{"username":"harry","password":"changeme"}' "200" test_ep "me with auth" GET "/api/me" "" "200" echo "--- Decks ---" test_ep "list decks" GET "/api/decks" "" "200" echo "--- Dashboard ---" test_ep "dashboard" GET "/api/dashboard" "" "200" echo "--- Tutorials ---" test_ep "list tutorials" GET "/api/tutorials" "" "200" echo "--- Cheatsheets ---" test_ep "list cheatsheets" GET "/api/cheatsheets" "" "200" echo "--- Quiz ---" test_ep "generate quiz" GET "/api/quiz/generate?count=3" "" "200" test_ep "quiz history" GET "/api/quiz/history" "" "200" echo "--- Admin ---" test_ep "import content" POST "/api/admin/import" '{}' "200" echo "--- Logout ---" test_ep "logout" POST "/api/logout" '{}' "200" test_ep "me after logout" GET "/api/me" "" "401" echo "" echo "=== Results: $PASS passed, $FAIL failed ===" rm -f "$COOKIE" [ "$FAIL" -eq 0 ] && exit 0 || exit 1