From ceeeb8fe4b49f1f4341fbf8d524d75a9d91d7c17 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Mon, 27 Mar 2023 09:33:25 -0600 Subject: [PATCH] test fillNonPlayerAliases --- src/device/input/parse/v01/server.go | 6 +++++- src/device/input/parse/v01/server_test.go | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/device/input/parse/v01/server.go b/src/device/input/parse/v01/server.go index 4c110c2..6793073 100644 --- a/src/device/input/parse/v01/server.go +++ b/src/device/input/parse/v01/server.go @@ -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 } diff --git a/src/device/input/parse/v01/server_test.go b/src/device/input/parse/v01/server_test.go index 5e0776f..f51cef5 100644 --- a/src/device/input/parse/v01/server_test.go +++ b/src/device/input/parse/v01/server_test.go @@ -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{