e2e/mentions_test.go

v1.30.0
gitbay/e2e/mentions_test.go history · blame · raw

92 lines · 3363 bytes

 1package e2e
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8// An @mention files an inbox row for the mentioned account and makes them
 9// a participant of the thread; watchers are not told about the mention,
10// mute holds, and someone who cannot read the repository is not reached
11// (#202).
12func TestMentionsNotify(t *testing.T) {
13	inst := startInstance(t)
14	keys := map[string]string{}
15	for _, u := range []string{"alice", "bob", "carol", "eve"} {
16		keys[u] = inst.newKey(t, u)
17		inst.admin(t, "admin", "user", "create", u, "--key", keys[u]+".pub")
18	}
19	if _, errOut, code := inst.ssh(t, keys["alice"], "", "repo", "create", "alice/app"); code != 0 {
20		t.Fatalf("repo create: %s", errOut)
21	}
22	if _, _, code := inst.ssh(t, keys["carol"], "", "repo", "watch", "alice/app"); code != 0 {
23		t.Fatal("watch failed")
24	}
25	summaries := func(key string) []string {
26		var out []string
27		for _, n := range notices(t, inst, key) {
28			out = append(out, n.Summary)
29		}
30		return out
31	}
32	has := func(list []string, want string) bool {
33		for _, s := range list {
34			if strings.Contains(s, want) {
35				return true
36			}
37		}
38		return false
39	}
40
41	// A mention in an issue body, with prose punctuation after the name.
42	if _, errOut, code := inst.ssh(t, keys["alice"], "", "issue", "create", "alice/app",
43		"--title", "'leak'", "--body", "'@bob, can you look? cc @nobody and @alice.'"); code != 0 {
44		t.Fatalf("issue create: %s", errOut)
45	}
46	if got := summaries(keys["bob"]); !has(got, "mentioned you in #1") {
47		t.Fatalf("bob not told about the mention: %v", got)
48	}
49	if got := summaries(keys["carol"]); has(got, "mentioned") || !has(got, "opened issue #1") {
50		t.Fatalf("watcher inbox: %v", got)
51	}
52	if got := summaries(keys["alice"]); has(got, "mentioned") {
53		t.Fatalf("self-mention filed: %v", got)
54	}
55
56	// bob is now a participant: a later comment reaches him.
57	if _, errOut, code := inst.ssh(t, keys["alice"], "", "issue", "comment", "alice/app", "1", "--message", "'more'"); code != 0 {
58		t.Fatalf("comment: %s", errOut)
59	}
60	if got := summaries(keys["bob"]); !has(got, "commented on #1") {
61		t.Fatalf("mentioned account not a participant: %v", got)
62	}
63
64	// Muted, a mention does not get through.
65	if _, _, code := inst.ssh(t, keys["bob"], "", "repo", "mute", "alice/app"); code != 0 {
66		t.Fatal("mute failed")
67	}
68	if _, errOut, code := inst.ssh(t, keys["alice"], "", "issue", "comment", "alice/app", "1", "--message", "'@bob again'"); code != 0 {
69		t.Fatalf("comment: %s", errOut)
70	}
71	if got := summaries(keys["bob"]); has(got, "mentioned you in #1") && len(got) > 2 {
72		t.Fatalf("mention reached a muted account: %v", got)
73	}
74
75	// A private repository: a mention of someone who cannot read it is
76	// dropped, one of someone who can is filed. Merge request bodies too.
77	for _, args := range [][]string{
78		{"repo", "create", "alice/secret", "--private"},
79		{"repo", "access", "grant", "alice/secret", "carol", "read"},
80		{"issue", "create", "alice/secret", "--title", "'hush'", "--body", "'@eve @carol'"},
81	} {
82		if _, errOut, code := inst.ssh(t, keys["alice"], "", args...); code != 0 {
83			t.Fatalf("%v: %s", args, errOut)
84		}
85	}
86	if got := summaries(keys["eve"]); len(got) != 0 {
87		t.Fatalf("outsider reached through a private repository: %v", got)
88	}
89	if got := summaries(keys["carol"]); !has(got, "mentioned you in #1") {
90		t.Fatalf("reader of a private repository not told: %v", got)
91	}
92}