From 5109dc9fdbaa9cb9d382fed5beecb540690b0f2f Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Sun, 15 Dec 2024 13:16:04 -0700 Subject: [PATCH] test usergameserver.State after game completes WOO --- cmd/server/usergameserver_test.go | 79 ++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/cmd/server/usergameserver_test.go b/cmd/server/usergameserver_test.go index be69fb8..9c81892 100644 --- a/cmd/server/usergameserver_test.go +++ b/cmd/server/usergameserver_test.go @@ -208,7 +208,84 @@ func TestUserGameServer(t *testing.T) { } }) + if err := games.CreateEventGameComplete(ctx, gid); err != nil { + t.Fatal(err) + } + t.Run("completed", func(t *testing.T) { - t.Error("not impl") + state, err := ugs.State(ctx) + if err != nil { + t.Fatal(err) + } + + if !state.Started { + t.Error("not started after complete") + } + + if state.Completed.IsZero() { + t.Error("not complete after complete") + } + + for _, pid := range pids { + p, ok := state.Players[pid] + if !ok { + t.Error(pid, "not in players") + } else if p.Empty() { + t.Error(pid, p) + } else if p.KillWords.Assigned.IsZero() { + t.Error("assigned is zero") + } + + if isSelf := pid == ugs.Session.ID; isSelf { + if len(p.Kills) == 0 { + t.Error("self never got a kill") + } else if kill := p.Kills[0]; kill.Timestamp.IsZero() { + t.Errorf("kill has no timestamp") + } else if kill.Victim == "" { + t.Errorf("kill has no victim") + } else if kill.KillWord.Points == 0 { + t.Errorf("dont know points of own kill at game review") + } else if kill.KillWord.Word == "" { + t.Errorf("dont know own kill word") + } + if p.KillWords.Global.Word == "" || p.KillWords.Global.Points == 0 { + t.Error("self global missing field") + } + if p.KillWords.Assignee == "" { + t.Error("assignee is empty") + } + if len(p.KillWords.Assignment.Public) == 0 { + t.Error("self doesnt know its own public after game") + } + if len(p.KillWords.Assignment.Private) == 0 { + t.Error("self doesnt know its own private after game") + } + } else { + if len(p.Kills) == 0 { + } else if kill := p.Kills[0]; kill.Timestamp.IsZero() { + t.Errorf("kill has no timestamp") + } else if kill.Victim == "" { + t.Errorf("cannot know other's victim") + } else if kill.KillWord.Points == 0 { + t.Errorf("other's kill has no points") + } else if kill.KillWord.Word == "" { + t.Errorf("dont know other's kill word") + } + if p.KillWords.Global.Empty() { + t.Error("cannot see not self global") + } + if p.KillWords.Assignee == "" { + t.Error("cannot see other player's assignee") + } + if len(p.KillWords.Assignment.Public) == 0 { + t.Error("cannot see other player's public") + } + if state.Players[ugs.Session.ID].KillWords.Assignee == pid && len(p.KillWords.Assignment.Private) == 0 { + t.Error("cannot see assignee's private") + } else if state.Players[ugs.Session.ID].KillWords.Assignee != pid && len(p.KillWords.Assignment.Private) == 0 { + t.Error("cannot see not assignee's private after game") + } + } + } }) }