internal/control/commentkind_test.go
51 lines · 1462 bytes
1 symbol in this file
1package control
2
3import (
4 "bytes"
5 "encoding/json"
6 "testing"
7
8 "gitbay.org/gitbay/internal/protocol"
9 "gitbay.org/gitbay/internal/store"
10)
11
12// A line the server posted (a label change, a retarget) says so in
13// --json; a client that offers reactions must not offer them on one, since
14// issue react and mr react refuse it. A comment carries no kind, so the
15// wire shape of every existing comment is unchanged.
16func TestShowMarksSystemComments(t *testing.T) {
17 st, repo, uid := newQueueTestRepo(t)
18 id, err := st.CreateIssue(repo.ID, uid, "t", "", "md")
19 if err != nil {
20 t.Fatal(err)
21 }
22 if err := st.AddIssueComment(id, uid, "me too", "md"); err != nil {
23 t.Fatal(err)
24 }
25 if err := st.AddIssueSystemComment(id, uid, "added label bug"); err != nil {
26 t.Fatal(err)
27 }
28 c, errOut := pruneCtx(st, t.TempDir(), store.User{ID: uid, Username: "alice"})
29 c.JSON = true
30 if code := Dispatch(c, []string{"issue", "show", repo.Path(), "1"}); code != protocol.ExitOK {
31 t.Fatalf("exit %d: %s", code, errOut)
32 }
33 var env struct {
34 Data struct {
35 Comments []map[string]any `json:"comments"`
36 } `json:"data"`
37 }
38 if err := json.Unmarshal(c.Stdout.(*bytes.Buffer).Bytes(), &env); err != nil {
39 t.Fatal(err)
40 }
41 cs := env.Data.Comments
42 if len(cs) != 2 {
43 t.Fatalf("comments: %v", cs)
44 }
45 if _, ok := cs[0]["kind"]; ok {
46 t.Errorf("a comment carries a kind: %v", cs[0])
47 }
48 if cs[1]["kind"] != "system" {
49 t.Errorf("a system line is not marked: %v", cs[1])
50 }
51}