diff --git a/src/device/input/parse/v01/server.go b/src/device/input/parse/v01/server.go index 5482e4b..f54519a 100644 --- a/src/device/input/parse/v01/server.go +++ b/src/device/input/parse/v01/server.go @@ -274,6 +274,7 @@ func (v01 *V01) serveGMVote(w http.ResponseWriter, r *http.Request) { v, ok := v01.cfg.Users[voter] if _, ok2 := v01.cfg.Users[candidate]; !ok || !ok2 { http.Error(w, "bad voter/candidate", http.StatusBadRequest) + return } v.Message = strings.Split(v.Message, "//")[0] + "//" + candidate v01.cfg.Users[voter] = v diff --git a/src/device/input/parse/v01/server_test.go b/src/device/input/parse/v01/server_test.go index 9efbc46..41ad150 100644 --- a/src/device/input/parse/v01/server_test.go +++ b/src/device/input/parse/v01/server_test.go @@ -241,8 +241,25 @@ func TestServeGM(t *testing.T) { t.Run("vote", func(t *testing.T) { type result map[string]string + t.Run("cast bad vote", func(t *testing.T) { + v01 := NewV01(ctx, nil) + v01.cfg.Users = map[string]configUser{"bel": {}} + resp := do(v01, "/gm/rpc/vote?user=bel&payload=?", "") + if resp.Code != http.StatusBadRequest { + t.Error(resp) + } + if v01.cfg.Users["bel"].Message != "" { + t.Error(v01.cfg.Users["bel"].Message) + } + }) + t.Run("cast vote", func(t *testing.T) { - t.Error("not impl") + v01 := NewV01(ctx, nil) + v01.cfg.Users = map[string]configUser{"bel": {}, "zach": {}} + do(v01, "/gm/rpc/vote?user=bel&payload=zach", "") + if v01.cfg.Users["bel"].Message != "//zach" { + t.Error(v01.cfg.Users["bel"].Message) + } }) t.Run("get non vote", func(t *testing.T) {