Added seperate bracket/node logic

This commit is contained in:
2026-02-12 16:03:10 +01:00 Verified
parent 7cbb7faca8
commit bb68e326cd
13 changed files with 540 additions and 530 deletions
+34 -33
View File
@@ -15,21 +15,22 @@ async def test_scoring_flow(
t_id = res.json()["id"]
t_code = valid_tournament_payload["code"]
# 2. Get Matches to find a Round 1 match
matches_res = await client.get(f"/tournaments/{t_id}/matches")
matches = matches_res.json()
# 2. Get Bracket Nodes (Updated Endpoint)
bracket_res = await client.get(f"/tournaments/{t_id}/bracket")
nodes = bracket_res.json()
# Find a match that has real players (not BYE)
# In double elim, Round 1 matches usually have seeds.
target_match = next(m for m in matches if m["p1"] and m["p2"])
match_id = target_match["id"]
next_match_id = target_match["next_win"] # Note: using alias from schema
# Find active node
active_node = next(n for n in nodes if n.get("match") is not None)
# 3. Report Score WITHOUT Auth Header (Public user with Code)
match_data = active_node["match"]
match_id = match_data["id"]
next_node_id = active_node["winner_next_node_id"]
# 3. Report Score
score_payload = {
"id": match_id,
"code": t_code,
"sets": [{"p1": 21, "p2": 19}, {"p1": 21, "p2": 15}], # P1 Wins
"sets": [{"p1": 21, "p2": 19}, {"p1": 21, "p2": 15}],
}
report_res = await client.post(
@@ -37,15 +38,17 @@ async def test_scoring_flow(
)
assert report_res.status_code == 200
# 4. Verify Winner Advanced
# Fetch the *Next* match
next_match_res = await client.get(f"/tournaments/{t_id}/matches/{next_match_id}")
next_match = next_match_res.json()
# 4. Verify Winner Advanced (Fetch bracket again)
updated_res = await client.get(f"/tournaments/{t_id}/bracket")
updated_nodes = updated_res.json()
# Assert P1 from previous match is now in the next match
# Note: We check if the name matches the winner
winner_name = target_match["p1"]
assert (next_match["p1"] == winner_name) or (next_match["p2"] == winner_name)
target_node = next(n for n in updated_nodes if n["id"] == next_node_id)
winner_id = match_data["p1_team"]["id"]
p1_in_target = target_node["p1_team"]["id"] if target_node["p1_team"] else None
p2_in_target = target_node["p2_team"]["id"] if target_node["p2_team"] else None
assert winner_id in [p1_in_target, p2_in_target]
# 5. Test Invalid Code
bad_payload = score_payload.copy()
@@ -57,38 +60,36 @@ async def test_scoring_flow(
async def test_clear_score(client: AsyncClient, auth_headers, valid_tournament_payload):
# Setup: Create & Score
# Setup
res = await client.post(
"/tournaments", json=valid_tournament_payload, headers=auth_headers
)
t_id = res.json()["id"]
matches = (await client.get(f"/tournaments/{t_id}/matches")).json()
target = next(m for m in matches if m["p1"] and m["p2"])
score_payload = {"id": target["id"], "code": "1234", "sets": [{"p1": 25, "p2": 0}]}
# Get active match
bracket = (await client.get(f"/tournaments/{t_id}/bracket")).json()
active_node = next(n for n in bracket if n.get("match"))
match_id = active_node["match"]["id"]
score_payload = {"id": match_id, "code": "1234", "sets": [{"p1": 25, "p2": 0}]}
await client.post(
f"/tournaments/{t_id}/matches/{target['id']}/score", json=score_payload
f"/tournaments/{t_id}/matches/{match_id}/score", json=score_payload
)
# Verify Finished
check_res = await client.get(f"/tournaments/{t_id}/matches/{target['id']}")
check_res = await client.get(f"/tournaments/{t_id}/matches/{match_id}")
assert check_res.json()["status"] == "Finished"
# Action: Clear Score
clear_res = await client.delete(
f"/tournaments/{t_id}/matches/{target['id']}/score", headers=auth_headers
f"/tournaments/{t_id}/matches/{match_id}/score", headers=auth_headers
)
assert clear_res.status_code == 200
# Verify Reset
final_res = await client.get(f"/tournaments/{t_id}/matches/{target['id']}")
final_res = await client.get(f"/tournaments/{t_id}/matches/{match_id}")
data = final_res.json()
# 1. We already fixed this to expect 'Scheduled'
assert data["status"] == "Scheduled"
# 2. FIX: Check 'winner_side' instead of 'winner'
# Use the Enum value "none"
assert data["winner_side"] == "none"
assert data["status"] == "Pending"
assert data["winner_team_id"] is None
assert len(data["sets"]) == 0