Refactor bracket validation logic to support draft state
Some checks failed
CI / backend (push) Has been cancelled
CI / frontend (push) Has been cancelled
CI / compose (push) Has been cancelled

This commit updates the bracket validation process by introducing a new `ValidateDraft` method, allowing for incomplete edits in the draft state. The existing `Validate` method has been modified to enforce complete validation only upon confirmation. Additionally, new tests have been added to ensure that incomplete drafts are accepted until confirmation, while still rejecting invalid references. Documentation has been updated to reflect these changes in the API and architecture.
This commit is contained in:
2026-07-19 13:43:25 +03:00
parent 6b189bfce4
commit a311b7761d
6 changed files with 53 additions and 7 deletions

View File

@@ -49,3 +49,34 @@ func TestBracketRejectsForwardReferencesAndMultipleFinals(t *testing.T) {
t.Fatal("expected invalid graph")
}
}
func TestBracketDraftAllowsIncompleteEditsUntilConfirmation(t *testing.T) {
draft := BracketDraft{
EventID: "event", TeamIDs: []string{"a", "b"},
Matches: []BracketMatch{
{ID: "m1", Round: 0, SlotA: SlotSource{Kind: SlotTeam, TeamID: "a"}, SlotB: SlotSource{Kind: SlotTeam, TeamID: "b"}},
{ID: "m2", Round: 1, SlotA: SlotSource{Kind: SlotWinner, MatchID: "m1"}, SlotB: SlotSource{Kind: SlotTeam}},
{ID: "m3", Round: 1, Order: 1, SlotA: SlotSource{Kind: SlotTeam, TeamID: "a"}, SlotB: SlotSource{Kind: SlotTeam, TeamID: "a"}},
},
}
if err := draft.ValidateDraft(); err != nil {
t.Fatalf("incomplete editable draft was rejected: %v", err)
}
if err := draft.Validate(); err == nil {
t.Fatal("expected incomplete bracket to be rejected at confirmation")
}
}
func TestBracketDraftStillRejectsInvalidReferences(t *testing.T) {
draft := BracketDraft{
EventID: "event", TeamIDs: []string{"a", "b"},
Matches: []BracketMatch{
{ID: "m1", Round: 0, SlotA: SlotSource{Kind: SlotWinner, MatchID: "missing"}, SlotB: SlotSource{Kind: SlotTeam}},
},
}
if err := draft.ValidateDraft(); err == nil {
t.Fatal("expected invalid match reference to be rejected")
}
}