139 lines
4.7 KiB
Python
Executable File
139 lines
4.7 KiB
Python
Executable File
import sys
|
|
from starlette.testclient import TestClient
|
|
from app.main import app
|
|
|
|
def test_endpoints():
|
|
client = TestClient(app)
|
|
|
|
# Test pages
|
|
res = client.get("/")
|
|
assert res.status_code == 200, f"Index failed: {res.status_code}"
|
|
assert "Die Kammern des Steins der Weisen" in res.text
|
|
assert "Zauberer-Cockpit" in res.text
|
|
|
|
res = client.get("/broom")
|
|
assert res.status_code == 200
|
|
assert "Der Goldene Ring-Flug" in res.text
|
|
|
|
res = client.get("/duel")
|
|
assert res.status_code == 200
|
|
assert "Das Zauberspruch-Duell" in res.text
|
|
|
|
# Test /chess redirects to /duel
|
|
res = client.get("/chess", follow_redirects=False)
|
|
assert res.status_code in [301, 302]
|
|
assert res.headers["location"] == "/duel"
|
|
|
|
# Test new mini-games: Brew, Cryptex, Pixies
|
|
res = client.get("/brew")
|
|
assert res.status_code == 200
|
|
assert "Die Zaubertrank-Brauküche" in res.text
|
|
assert "Felix Felicis" in res.text
|
|
|
|
res = client.get("/cryptex")
|
|
assert res.status_code == 200
|
|
assert "Das Runen-Drehschloss" in res.text
|
|
|
|
res = client.get("/pixies")
|
|
assert res.status_code == 200
|
|
assert "Wichtel-Panik" in res.text
|
|
|
|
res = client.get("/bottles")
|
|
assert res.status_code == 200
|
|
assert "Snapes Flaschenrätsel" in res.text
|
|
|
|
res = client.get("/sliding")
|
|
assert res.status_code == 200
|
|
assert "Alchemie-Schieberätsel" in res.text
|
|
|
|
res = client.get("/finale")
|
|
assert res.status_code == 200
|
|
assert "ESCAPE GEMEISTERT" in res.text
|
|
|
|
# Test Inventory API
|
|
res = client.get("/api/inventory")
|
|
assert res.status_code == 200
|
|
inv_data = res.json()
|
|
assert "inventory" in inv_data
|
|
assert len(inv_data["inventory"]) >= 3
|
|
item_ids = [item["id"] for item in inv_data["inventory"]]
|
|
assert "wand" in item_ids
|
|
assert "broom" in item_ids
|
|
assert "snape_scroll" in item_ids
|
|
|
|
# Test House API
|
|
res = client.post("/api/player/house", json={"house": "ravenclaw"})
|
|
assert res.status_code == 200
|
|
assert res.json()["house"]["name"] == "Ravenclaw"
|
|
|
|
# Test API Broom complete (adds winged_key)
|
|
res = client.post("/api/broom/complete", json={"score": 850, "time_taken": 22})
|
|
assert res.status_code == 200
|
|
assert res.json()["success"] is True
|
|
assert res.json()["new_item"]["id"] == "winged_key"
|
|
|
|
# Test API Duel complete (adds duel_badge)
|
|
res = client.post("/api/duel/complete")
|
|
assert res.status_code == 200
|
|
duel_data = res.json()
|
|
assert duel_data["success"] is True
|
|
assert duel_data["new_item"]["id"] == "duel_badge"
|
|
|
|
# Test API Brew complete (adds felix_felicis)
|
|
res = client.post("/api/brew/complete")
|
|
assert res.status_code == 200
|
|
brew_data = res.json()
|
|
assert brew_data["success"] is True
|
|
assert brew_data["new_item"]["id"] == "felix_felicis"
|
|
|
|
# Test API Cryptex unlock (wrong then correct)
|
|
res = client.post("/api/cryptex/unlock", json={"combination": ["🐍", "☀️", "💧", "🗝️"]})
|
|
assert res.status_code == 200
|
|
assert res.json()["success"] is False
|
|
|
|
res = client.post("/api/cryptex/unlock", json={"combination": ["🦁", "🌙", "🔥", "🪄"]})
|
|
assert res.status_code == 200
|
|
cryp_data = res.json()
|
|
assert cryp_data["success"] is True
|
|
assert cryp_data["new_item"]["id"] == "cryptex_key"
|
|
|
|
# Test API Pixies complete (under 10 then >= 10)
|
|
res = client.post("/api/pixies/complete", json={"caught": 5})
|
|
assert res.status_code == 200
|
|
assert res.json()["success"] is False
|
|
|
|
res = client.post("/api/pixies/complete", json={"caught": 10})
|
|
assert res.status_code == 200
|
|
pix_data = res.json()
|
|
assert pix_data["success"] is True
|
|
assert pix_data["new_item"]["id"] == "pixie_jar"
|
|
|
|
# Verify updated inventory contains all items
|
|
res = client.get("/api/inventory")
|
|
updated_inv = res.json()
|
|
inv_ids = [item["id"] for item in updated_inv["inventory"]]
|
|
assert "duel_badge" in inv_ids
|
|
assert "felix_felicis" in inv_ids
|
|
assert "cryptex_key" in inv_ids
|
|
assert "pixie_jar" in inv_ids
|
|
assert updated_inv["brew_solved"] is True
|
|
assert updated_inv["cryptex_solved"] is True
|
|
assert updated_inv["pixies_solved"] is True
|
|
|
|
# Test API Bottles drink: Ahead / Black fire (Bottle 3 - Dwarf, adds philosophers_stone)
|
|
res = client.post("/api/bottles/drink", json={"bottle": 3, "gate": "ahead"})
|
|
assert res.status_code == 200
|
|
drink_data = res.json()
|
|
assert drink_data["result"] == "success_ahead"
|
|
assert drink_data["new_item"]["id"] == "philosophers_stone"
|
|
|
|
# Test API Reset
|
|
res = client.post("/api/reset")
|
|
assert res.status_code == 200
|
|
assert res.json()["success"] is True
|
|
|
|
print("ALL TESTS (ALL MINI-GAMES & APIS) PASSED! ⭕🪄⚗️🔐🧚🧪💎✨")
|
|
|
|
if __name__ == "__main__":
|
|
test_endpoints()
|