test a vote for someone saying themself
This commit is contained in:
@@ -241,6 +241,10 @@ func TestServeGM(t *testing.T) {
|
||||
t.Run("vote", func(t *testing.T) {
|
||||
type result map[string]string
|
||||
|
||||
t.Run("cast vote", func(t *testing.T) {
|
||||
t.Error("not impl")
|
||||
})
|
||||
|
||||
t.Run("get non vote", func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
v01.cfg.Users = map[string]configUser{"bel": {}}
|
||||
@@ -260,7 +264,7 @@ func TestServeGM(t *testing.T) {
|
||||
|
||||
t.Run("get mid vote", func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
v01.cfg.Users = map[string]configUser{"bel": {Alias: "//zach"}}
|
||||
v01.cfg.Users = map[string]configUser{"bel": {Message: "driver//zach"}}
|
||||
resp := do(v01, "/gm/rpc/vote", "", "GET")
|
||||
var result result
|
||||
if err := yaml.Unmarshal(resp.Body.Bytes(), &result); err != nil {
|
||||
@@ -291,7 +295,107 @@ func TestServeGM(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("elect", func(t *testing.T) {
|
||||
t.Error("not impl")
|
||||
type result map[string]int
|
||||
|
||||
t.Run("happy", func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
v01.cfg.Users = map[string]configUser{
|
||||
"bel": configUser{Message: "driver//zach", Player: 1},
|
||||
"zach": configUser{Message: "pizza//bel"},
|
||||
"bill": configUser{Message: "//bel", Player: 2},
|
||||
}
|
||||
resp := do(v01, "/gm/rpc/elect?alias=pizza", "")
|
||||
var result result
|
||||
if err := yaml.Unmarshal(resp.Body.Bytes(), &result); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(result) != 2 {
|
||||
t.Error(result)
|
||||
} else if result["bel"] != 2 {
|
||||
t.Error(result)
|
||||
} else if result["zach"] != 1 {
|
||||
t.Error(result)
|
||||
}
|
||||
if v01.cfg.Users["bel"].Player != 0 {
|
||||
t.Error(v01.cfg.Users["bel"].Player)
|
||||
} else if v01.cfg.Users["zach"].Player != 1 {
|
||||
t.Error(v01.cfg.Users["zach"].Player)
|
||||
}
|
||||
if v01.cfg.Users["broadcast"].Message != `bel is now player 0 and zach is now player 1` {
|
||||
t.Error(v01.cfg.Users["broadcast"].Message)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("self", func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
v01.cfg.Players = []configPlayer{{}}
|
||||
v01.cfg.Users = map[string]configUser{
|
||||
"bel": configUser{Message: "driver//zach", Player: 1},
|
||||
"zach": configUser{Message: "//bel"},
|
||||
"bill": configUser{Message: "//bel"},
|
||||
}
|
||||
resp := do(v01, "/gm/rpc/elect?alias=driver", "")
|
||||
var result result
|
||||
if err := yaml.Unmarshal(resp.Body.Bytes(), &result); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(result) != 2 {
|
||||
t.Error(result)
|
||||
} else if result["bel"] != 2 {
|
||||
t.Error(result)
|
||||
} else if result["zach"] != 1 {
|
||||
t.Error(result)
|
||||
}
|
||||
if !strings.HasSuffix(v01.cfg.Users["broadcast"].Message, `is now player 1`) || strings.Contains(v01.cfg.Users["broadcast"].Message, ",") {
|
||||
t.Error(v01.cfg.Users["broadcast"].Message)
|
||||
}
|
||||
assignments := map[int]int{}
|
||||
for _, v := range v01.cfg.Users {
|
||||
assignments[v.Player] = assignments[v.Player] + 1
|
||||
}
|
||||
if len(assignments) != 2 {
|
||||
t.Error(assignments)
|
||||
} else if assignments[0] != 3 {
|
||||
t.Error(assignments[0])
|
||||
} else if assignments[1] != 1 {
|
||||
t.Error(assignments[1])
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("tie", func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
v01.cfg.Players = []configPlayer{{}}
|
||||
v01.cfg.Users = map[string]configUser{
|
||||
"bel": configUser{Message: "driver//zach", Player: 1},
|
||||
"zach": configUser{Message: "pizza//bel"},
|
||||
}
|
||||
resp := do(v01, "/gm/rpc/elect?alias=pizza", "")
|
||||
var result result
|
||||
if err := yaml.Unmarshal(resp.Body.Bytes(), &result); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(result) != 2 {
|
||||
t.Error(result)
|
||||
} else if result["bel"] != 1 {
|
||||
t.Error(result)
|
||||
} else if result["zach"] != 1 {
|
||||
t.Error(result)
|
||||
}
|
||||
if !strings.HasSuffix(v01.cfg.Users["broadcast"].Message, `is now player 1`) || strings.Contains(v01.cfg.Users["broadcast"].Message, ",") {
|
||||
t.Error(v01.cfg.Users["broadcast"].Message)
|
||||
}
|
||||
assignments := map[int]int{}
|
||||
for _, v := range v01.cfg.Users {
|
||||
assignments[v.Player] = assignments[v.Player] + 1
|
||||
}
|
||||
if len(assignments) != 2 {
|
||||
t.Error(assignments)
|
||||
} else if assignments[0] != 2 {
|
||||
t.Error(assignments[0])
|
||||
} else if assignments[1] != 1 {
|
||||
t.Error(assignments[1])
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("shuffle", func(t *testing.T) {
|
||||
@@ -367,10 +471,10 @@ func TestServeGM(t *testing.T) {
|
||||
t.Error(i)
|
||||
}
|
||||
}
|
||||
assignments := map[int]struct{}{}
|
||||
assignments := map[int]int{}
|
||||
for _, v := range v01.cfg.Users {
|
||||
if v.Player > 0 {
|
||||
assignments[v.Player] = struct{}{}
|
||||
assignments[v.Player] = assignments[v.Player] + 1
|
||||
}
|
||||
}
|
||||
lesser := c.users
|
||||
@@ -380,6 +484,11 @@ func TestServeGM(t *testing.T) {
|
||||
if len(assignments) != lesser {
|
||||
t.Error(assignments)
|
||||
}
|
||||
for _, v := range assignments {
|
||||
if v != 1 {
|
||||
t.Error(v)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user