impl,test fill non player aliases

master
Bel LaPointe 2023-03-27 09:30:29 -06:00
parent 0435f7b3e8
commit d029d82366
2 changed files with 43 additions and 2 deletions

View File

@ -159,7 +159,31 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
}
v01.servePutBroadcastValue(fmt.Sprintf("<<SOMEONE SAID %q>>", strings.ToUpper(r.URL.Query().Get("message"))))
case "/gm/rpc/fillNonPlayerAliases":
panic("TODO stash aliases")
b, _ := io.ReadAll(r.Body)
var pool []string
yaml.Unmarshal(b, &pool)
n := 0
for _, v := range v01.cfg.Users {
if v.Player == 0 {
n += 1
}
}
if len(b) < n {
http.Error(w, fmt.Sprintf("request body must contain a list of %v options", n), http.StatusBadRequest)
return
}
for i := 0; i < 100; i++ {
a, b := rand.Int()%len(pool), rand.Int()%len(pool)
pool[a], pool[b] = pool[b], pool[a]
}
i := 0
for k, v := range v01.cfg.Users {
if v.Player == 0 {
v.Alias = pool[i]
v01.cfg.Users[k] = v
i += 1
}
}
case "/gm/rpc/vote":
panic("TODO stash user:votedForUser")
case "/gm/rpc/elect":

View File

@ -194,7 +194,24 @@ func TestServeGM(t *testing.T) {
})
t.Run("fillNonPlayerAliases", func(t *testing.T) {
t.Error("not impl")
t.Run("happy", func(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Users = map[string]configUser{
"bel": configUser{Player: 1},
"zach": configUser{Player: 0},
}
do(v01, "/gm/rpc/fillNonPlayerAliases", "[qt]")
if v := v01.cfg.Users["bel"]; v.Alias != "" {
t.Error(v.Alias)
} else if v.Player != 1 {
t.Error(v.Player)
}
if v := v01.cfg.Users["zach"]; v.Alias != "qt" {
t.Error(v.Alias)
} else if v.Player != 0 {
t.Error(v.Player)
}
})
})
t.Run("vote", func(t *testing.T) {