Add player profiles and community settings
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
80
backend/internal/domain/player_profile_test.go
Normal file
80
backend/internal/domain/player_profile_test.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPlayerIdentityValidation(t *testing.T) {
|
||||
player := Player{DisplayName: " Ana Main ", BattleTag: "Ana#1234"}
|
||||
if err := player.ValidateIdentity(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if player.DisplayName != "Ana Main" {
|
||||
t.Fatalf("display name was not trimmed: %q", player.DisplayName)
|
||||
}
|
||||
player.DisplayName = "A"
|
||||
if !errors.Is(player.ValidateIdentity(), ErrInvalid) {
|
||||
t.Fatal("one-character display name must be invalid")
|
||||
}
|
||||
player.DisplayName, player.BattleTag = "Valid", "invalid"
|
||||
if !errors.Is(player.ValidateIdentity(), ErrInvalid) {
|
||||
t.Fatal("invalid BattleTag must be rejected")
|
||||
}
|
||||
player.BattleTag = ""
|
||||
if err := player.ValidateIdentity(); err != nil {
|
||||
t.Fatalf("empty BattleTag must clear the value: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildPlayerProfileUsesEffectiveResultsAndFinalRoster(t *testing.T) {
|
||||
start := time.Date(2026, time.July, 19, 18, 0, 0, 0, time.UTC)
|
||||
event := Event{ID: "event", Name: "Sunday Mix", StartsAt: start, State: Completed}
|
||||
teamA := Team{ID: "a", Name: "Alpha", Slots: []Slot{{PlayerID: "player"}}}
|
||||
teamB := Team{ID: "b", Name: "Bravo", Slots: []Slot{{PlayerID: "opponent"}}}
|
||||
series := Series{
|
||||
ID: "series", EventID: event.ID, TeamAID: teamA.ID, TeamBID: teamB.ID,
|
||||
WinnerTeamID: teamA.ID, Phase: SeriesComplete,
|
||||
Results: []MapResult{
|
||||
{Outcome: TeamBWin},
|
||||
{Outcome: TeamAWin},
|
||||
{Outcome: Draw},
|
||||
{Outcome: TeamAWin, CorrectionOf: 1},
|
||||
},
|
||||
}
|
||||
profile := BuildPlayerProfile(Player{ID: "player", DisplayName: "Player", AccountID: ""}, []PlayerSeriesContext{
|
||||
{Event: event, Series: series, TeamA: teamA, TeamB: teamB},
|
||||
{Event: Event{State: Live}, Series: series, TeamA: teamA, TeamB: teamB},
|
||||
{Event: event, Series: series, TeamA: Team{ID: "a"}, TeamB: teamB},
|
||||
}, 10)
|
||||
|
||||
if profile.Summary.SeriesPlayed != 1 || profile.Summary.SeriesWon != 1 || profile.Summary.WinRate != 1 {
|
||||
t.Fatalf("unexpected series summary: %+v", profile.Summary)
|
||||
}
|
||||
if profile.Summary.MapsPlayed != 3 || profile.Summary.MapsWon != 2 ||
|
||||
profile.Summary.MapsLost != 0 || profile.Summary.MapsDrawn != 1 {
|
||||
t.Fatalf("corrected map result was not aggregated correctly: %+v", profile.Summary)
|
||||
}
|
||||
if len(profile.Recent) != 1 || profile.Recent[0].OwnScore != 2 || profile.Recent[0].OpponentScore != 0 {
|
||||
t.Fatalf("unexpected history: %+v", profile.Recent)
|
||||
}
|
||||
if !profile.Player.IsGuest {
|
||||
t.Fatal("account-less players must be represented as guests")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommunitySettingsValidation(t *testing.T) {
|
||||
for _, value := range []string{"", "https://discord.gg/mixmaker", "https://discord.com/invite/mixmaker"} {
|
||||
settings := CommunitySettings{DiscordInviteURL: value}
|
||||
if err := settings.Validate(); err != nil {
|
||||
t.Fatalf("%q should be valid: %v", value, err)
|
||||
}
|
||||
}
|
||||
for _, value := range []string{"http://discord.gg/code", "https://example.com/invite", "https://discord.gg/", "https://discord.gg/code/path"} {
|
||||
settings := CommunitySettings{DiscordInviteURL: value}
|
||||
if !errors.Is(settings.Validate(), ErrInvalid) {
|
||||
t.Fatalf("%q should be invalid", value)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user