This commit introduces a new Discord event announcer to the backend, allowing for event announcements via Discord. It includes the addition of new environment variables for Discord configuration in `.env.example` and `compose.yaml`. The `main.go` file has been updated to initialize the announcer, and a new `discord` package has been created, containing the announcer logic and tests. Additionally, the service layer has been modified to support bracket draft management, enhancing the overall event workflow. Integration tests have been updated to ensure proper functionality of the new features.
52 lines
1.8 KiB
Go
52 lines
1.8 KiB
Go
package domain
|
|
|
|
import "testing"
|
|
|
|
func TestThreeTeamBracketResolvesWinnerAndLoserFeeds(t *testing.T) {
|
|
draft, err := NewBracketDraft("event", []string{"a", "b", "c"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tournament, err := NewGraphTournament("cup", "event", "Cup", *draft)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ready := tournament.ReadyMatches()
|
|
if len(ready) != 1 || ready[0].TeamAID != "a" || ready[0].TeamBID != "b" {
|
|
t.Fatalf("unexpected first match: %#v", ready)
|
|
}
|
|
if err = tournament.ApplySeries(Series{ID: ready[0].ID, TeamAID: "a", TeamBID: "b", WinnerTeamID: "a"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ready = tournament.ReadyMatches()
|
|
if len(ready) != 1 || ready[0].TeamAID != "b" || ready[0].TeamBID != "c" {
|
|
t.Fatalf("loser feed was not resolved: %#v", ready)
|
|
}
|
|
if err = tournament.ApplySeries(Series{ID: ready[0].ID, TeamAID: "b", TeamBID: "c", WinnerTeamID: "c"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ready = tournament.ReadyMatches()
|
|
if len(ready) != 1 || ready[0].TeamAID != "a" || ready[0].TeamBID != "c" {
|
|
t.Fatalf("final feed was not resolved: %#v", ready)
|
|
}
|
|
if err = tournament.ApplySeries(Series{ID: ready[0].ID, TeamAID: "a", TeamBID: "c", WinnerTeamID: "c"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !tournament.Complete() || tournament.WinnerTeamID != "c" {
|
|
t.Fatalf("unexpected champion: %q", tournament.WinnerTeamID)
|
|
}
|
|
}
|
|
|
|
func TestBracketRejectsForwardReferencesAndMultipleFinals(t *testing.T) {
|
|
draft := BracketDraft{
|
|
EventID: "event", TeamIDs: []string{"a", "b"},
|
|
Matches: []BracketMatch{
|
|
{ID: "m1", Round: 0, SlotA: SlotSource{Kind: SlotWinner, MatchID: "m2"}, SlotB: SlotSource{Kind: SlotTeam, TeamID: "a"}},
|
|
{ID: "m2", Round: 0, Order: 1, SlotA: SlotSource{Kind: SlotTeam, TeamID: "a"}, SlotB: SlotSource{Kind: SlotTeam, TeamID: "b"}},
|
|
},
|
|
}
|
|
if err := draft.Validate(); err == nil {
|
|
t.Fatal("expected invalid graph")
|
|
}
|
|
}
|