Better bracket logic
This commit is contained in:
@@ -15,16 +15,19 @@ async def test_scoring_flow(
|
||||
t_id = res.json()["id"]
|
||||
t_code = valid_tournament_payload["code"]
|
||||
|
||||
# 2. Get Bracket Nodes (Updated Endpoint)
|
||||
bracket_res = await client.get(f"/tournaments/{t_id}/bracket")
|
||||
nodes = bracket_res.json()
|
||||
# 2. Get Bracket (Now returns list of Matches)
|
||||
# Note: You can now get this from GET /tournaments/{id} or /bracket depending on your routes
|
||||
bracket_res = await client.get(f"/tournaments/{t_id}")
|
||||
matches = bracket_res.json()["matches"]
|
||||
|
||||
# Find active node
|
||||
active_node = next(n for n in nodes if n.get("match") is not None)
|
||||
# Find the first playable match (Round 1)
|
||||
# We look for a match that has teams assigned but is not finished
|
||||
active_match = next(
|
||||
m for m in matches if m["status"] == "Pending" and m["p1_team"] and m["p2_team"]
|
||||
)
|
||||
|
||||
match_data = active_node["match"]
|
||||
match_id = match_data["id"]
|
||||
next_node_id = active_node["winner_next_node_id"]
|
||||
match_id = active_match["id"]
|
||||
next_match_id = active_match["winner_next_match_id"]
|
||||
|
||||
# 3. Report Score
|
||||
score_payload = {
|
||||
@@ -38,15 +41,17 @@ async def test_scoring_flow(
|
||||
)
|
||||
assert report_res.status_code == 200
|
||||
|
||||
# 4. Verify Winner Advanced (Fetch bracket again)
|
||||
updated_res = await client.get(f"/tournaments/{t_id}/bracket")
|
||||
updated_nodes = updated_res.json()
|
||||
# 4. Verify Winner Advanced
|
||||
updated_res = await client.get(f"/tournaments/{t_id}")
|
||||
updated_matches = updated_res.json()["matches"]
|
||||
|
||||
target_node = next(n for n in updated_nodes if n["id"] == next_node_id)
|
||||
target_match = next(m for m in updated_matches if m["id"] == next_match_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
|
||||
winner_id = active_match["p1_team"]["id"]
|
||||
|
||||
# Check if winner is now in the next match
|
||||
p1_in_target = target_match["p1_team"]["id"] if target_match["p1_team"] else None
|
||||
p2_in_target = target_match["p2_team"]["id"] if target_match["p2_team"] else None
|
||||
|
||||
assert winner_id in [p1_in_target, p2_in_target]
|
||||
|
||||
@@ -67,9 +72,9 @@ async def test_clear_score(client: AsyncClient, auth_headers, valid_tournament_p
|
||||
t_id = res.json()["id"]
|
||||
|
||||
# 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"]
|
||||
detail = (await client.get(f"/tournaments/{t_id}")).json()
|
||||
active_match = next(m for m in detail["matches"] if m["p1_team"] and m["p2_team"])
|
||||
match_id = active_match["id"]
|
||||
|
||||
score_payload = {"id": match_id, "code": "1234", "sets": [{"p1": 25, "p2": 0}]}
|
||||
await client.post(
|
||||
|
||||
Reference in New Issue
Block a user