test fillNonPlayerAliases

master
Bel LaPointe 2023-03-27 09:33:25 -06:00
parent d029d82366
commit ceeeb8fe4b
2 changed files with 25 additions and 1 deletions

View File

@ -168,7 +168,11 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
n += 1
}
}
if len(b) < n {
if n < 1 {
w.WriteHeader(http.StatusNoContent)
return
}
if len(pool) < n {
http.Error(w, fmt.Sprintf("request body must contain a list of %v options", n), http.StatusBadRequest)
return
}

View File

@ -194,6 +194,26 @@ func TestServeGM(t *testing.T) {
})
t.Run("fillNonPlayerAliases", func(t *testing.T) {
t.Run("empty", func(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Users = nil
resp := do(v01, "/gm/rpc/fillNonPlayerAliases", "[qt]")
if resp.Code != http.StatusNoContent {
t.Error(resp.Code)
}
})
t.Run("not enough", func(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Users = map[string]configUser{
"zach": configUser{Player: 0},
}
resp := do(v01, "/gm/rpc/fillNonPlayerAliases", "[]")
if resp.Code != http.StatusBadRequest {
t.Error(resp.Code)
}
})
t.Run("happy", func(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Users = map[string]configUser{