99 lines
3.1 KiB
Bash
Executable File
99 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
if [ -z "${BASE_URL:-}" ]; then
|
|
if curl --silent --fail http://127.0.0.1:8085/api/health >/dev/null 2>&1; then
|
|
BASE_URL="http://127.0.0.1:8085"
|
|
elif curl --silent --fail http://host.containers.internal:8085/api/health >/dev/null 2>&1; then
|
|
BASE_URL="http://host.containers.internal:8085"
|
|
else
|
|
echo "ERROR: could not determine BASE_URL. Tried 127.0.0.1 and host.containers.internal." >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
SERIES_ID="${SERIES_ID:-430543}"
|
|
TMP_DIR="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
|
|
|
echo "== Feature test 1: episodes endpoint returns series + items =="
|
|
curl --fail --silent --show-error \
|
|
"${BASE_URL}/api/tvdb/series/${SERIES_ID}/episodes?order_type=aired" \
|
|
-o "${TMP_DIR}/episodes.json"
|
|
|
|
cat "${TMP_DIR}/episodes.json"
|
|
|
|
python3 - "${TMP_DIR}/episodes.json" <<'PY'
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
path = Path(sys.argv[1])
|
|
data = json.loads(path.read_text(encoding="utf-8"))
|
|
|
|
assert isinstance(data, dict), "episodes response must be an object"
|
|
assert "series" in data and isinstance(data["series"], dict), "episodes response missing series object"
|
|
assert data.get("order_type") == "aired", "order_type must be aired"
|
|
assert "items" in data and isinstance(data["items"], list), "episodes response missing items list"
|
|
|
|
series = data["series"]
|
|
for key in ["id", "name", "year", "display_name"]:
|
|
assert key in series, f"series missing key: {key}"
|
|
|
|
print("episodes endpoint JSON validation passed")
|
|
PY
|
|
|
|
echo
|
|
echo "== Feature test 2: unsupported order_type is rejected =="
|
|
curl --silent --show-error \
|
|
-o "${TMP_DIR}/episodes_bad_order.json" \
|
|
-w "%{http_code}" \
|
|
"${BASE_URL}/api/tvdb/series/${SERIES_ID}/episodes?order_type=absolute" \
|
|
> "${TMP_DIR}/episodes_bad_order.status"
|
|
|
|
cat "${TMP_DIR}/episodes_bad_order.json"
|
|
|
|
python3 - "${TMP_DIR}/episodes_bad_order.status" "${TMP_DIR}/episodes_bad_order.json" <<'PY'
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
status = Path(sys.argv[1]).read_text(encoding="utf-8").strip()
|
|
data = json.loads(Path(sys.argv[2]).read_text(encoding="utf-8"))
|
|
|
|
assert status == "400", f"expected HTTP 400, got {status}"
|
|
assert isinstance(data, dict), "error response must be an object"
|
|
assert "detail" in data, "error response missing detail"
|
|
|
|
print("unsupported order_type validation passed")
|
|
PY
|
|
|
|
echo
|
|
echo "== Feature test 3: search output keeps year/display_name contract =="
|
|
curl --fail --silent --show-error \
|
|
"${BASE_URL}/api/tvdb/search?q=elsbeth" \
|
|
-o "${TMP_DIR}/search.json"
|
|
|
|
cat "${TMP_DIR}/search.json"
|
|
|
|
python3 - "${TMP_DIR}/search.json" <<'PY'
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
path = Path(sys.argv[1])
|
|
data = json.loads(path.read_text(encoding="utf-8"))
|
|
|
|
assert isinstance(data, dict), "search response must be an object"
|
|
assert "items" in data and isinstance(data["items"], list), "search response missing items list"
|
|
assert len(data["items"]) > 0, "search items list must not be empty"
|
|
|
|
first = data["items"][0]
|
|
for key in ["id", "name", "year", "display_name"]:
|
|
assert key in first, f"search item missing key: {key}"
|
|
|
|
print("search contract validation passed")
|
|
PY
|
|
|
|
echo
|
|
echo "All episodes feature tests passed."
|