Refactor bracket validation logic to support draft state
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:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user