e2e/watchpref_test.go
78 lines · 3398 bytes
1 symbol in this file
1package e2e
2
3import (
4 "net/url"
5 "strings"
6 "testing"
7)
8
9// notifications settings watch on makes an account a recipient of every
10// issue on the repositories it can write to, with no repo watch row;
11// read access is not enough, and off returns it to the default. The
12// account page carries the same switch (#194).
13func TestWatchPreference(t *testing.T) {
14 t.Parallel()
15 inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
16 aliceKey := inst.newKey(t, "alice")
17 bobKey := inst.newKey(t, "bob")
18 carolKey := inst.newKey(t, "carol")
19 daveKey := inst.newKey(t, "dave")
20 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
21 inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub")
22 inst.admin(t, "admin", "user", "create", "carol", "--key", carolKey+".pub")
23 inst.admin(t, "admin", "user", "create", "dave", "--key", daveKey+".pub")
24 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
25 t.Fatalf("repo create: %s", errOut)
26 }
27 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "access", "grant", "alice/app", "bob", "write"); code != 0 {
28 t.Fatalf("grant bob: %s", errOut)
29 }
30 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "access", "grant", "alice/app", "carol", "read"); code != 0 {
31 t.Fatalf("grant carol: %s", errOut)
32 }
33
34 out, _, code := inst.ssh(t, bobKey, "", "notifications", "settings", "show", "--json")
35 if code != 0 || !strings.Contains(out, `"watch":false`) {
36 t.Fatalf("settings show: %d %s", code, out)
37 }
38 if _, _, code := inst.ssh(t, bobKey, "", "notifications", "settings", "watch", "maybe"); code != 2 {
39 t.Fatalf("bad value accepted: %d", code)
40 }
41 for _, key := range []string{bobKey, carolKey} {
42 if out, _, code := inst.ssh(t, key, "", "notifications", "settings", "watch", "on", "--json"); code != 0 || !strings.Contains(out, `"watch":true`) {
43 t.Fatalf("watch on: %d %s", code, out)
44 }
45 }
46
47 if _, errOut, code := inst.ssh(t, daveKey, "", "issue", "create", "alice/app", "--title", "'first'"); code != 0 {
48 t.Fatalf("issue create: %s", errOut)
49 }
50 if rows := notices(t, inst, bobKey); len(rows) != 1 || !strings.Contains(rows[0].Summary, "opened issue #1") {
51 t.Fatalf("writer's inbox: %+v", rows)
52 }
53 if rows := notices(t, inst, carolKey); len(rows) != 0 {
54 t.Fatalf("reader's inbox: %+v", rows)
55 }
56 if out, _, _ := inst.ssh(t, bobKey, "", "repo", "show", "alice/app", "--json"); strings.Contains(out, `"watch":"watching"`) {
57 t.Fatalf("preference wrote a watch row: %s", out)
58 }
59
60 // The account page shows it on and turns it off.
61 bob := inst.login(t, bobKey)
62 set := inst.base() + "/settings"
63 if _, body := browserGet(t, bob, set); !strings.Contains(body, `name="watch" value="on" checked`) {
64 t.Fatalf("account page does not show watch on:\n%s", body)
65 }
66 if status, _ := browserPost(t, bob, set, url.Values{"field": {"notify-watch"}}); status != 200 {
67 t.Fatalf("settings post: %d", status)
68 }
69 if out, _, _ := inst.ssh(t, bobKey, "", "notifications", "settings", "show", "--json"); !strings.Contains(out, `"watch":false`) {
70 t.Fatalf("web toggle did not turn watch off: %s", out)
71 }
72 if _, errOut, code := inst.ssh(t, daveKey, "", "issue", "create", "alice/app", "--title", "'second'"); code != 0 {
73 t.Fatalf("second issue: %s", errOut)
74 }
75 if rows := notices(t, inst, bobKey); len(rows) != 1 {
76 t.Fatalf("inbox after watch off: %+v", rows)
77 }
78}