e2e/watchpref_test.go
77 lines · 3384 bytes
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 inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
15 aliceKey := inst.newKey(t, "alice")
16 bobKey := inst.newKey(t, "bob")
17 carolKey := inst.newKey(t, "carol")
18 daveKey := inst.newKey(t, "dave")
19 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
20 inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub")
21 inst.admin(t, "admin", "user", "create", "carol", "--key", carolKey+".pub")
22 inst.admin(t, "admin", "user", "create", "dave", "--key", daveKey+".pub")
23 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
24 t.Fatalf("repo create: %s", errOut)
25 }
26 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "access", "grant", "alice/app", "bob", "write"); code != 0 {
27 t.Fatalf("grant bob: %s", errOut)
28 }
29 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "access", "grant", "alice/app", "carol", "read"); code != 0 {
30 t.Fatalf("grant carol: %s", errOut)
31 }
32
33 out, _, code := inst.ssh(t, bobKey, "", "notifications", "settings", "show", "--json")
34 if code != 0 || !strings.Contains(out, `"watch":false`) {
35 t.Fatalf("settings show: %d %s", code, out)
36 }
37 if _, _, code := inst.ssh(t, bobKey, "", "notifications", "settings", "watch", "maybe"); code != 2 {
38 t.Fatalf("bad value accepted: %d", code)
39 }
40 for _, key := range []string{bobKey, carolKey} {
41 if out, _, code := inst.ssh(t, key, "", "notifications", "settings", "watch", "on", "--json"); code != 0 || !strings.Contains(out, `"watch":true`) {
42 t.Fatalf("watch on: %d %s", code, out)
43 }
44 }
45
46 if _, errOut, code := inst.ssh(t, daveKey, "", "issue", "create", "alice/app", "--title", "'first'"); code != 0 {
47 t.Fatalf("issue create: %s", errOut)
48 }
49 if rows := notices(t, inst, bobKey); len(rows) != 1 || !strings.Contains(rows[0].Summary, "opened issue #1") {
50 t.Fatalf("writer's inbox: %+v", rows)
51 }
52 if rows := notices(t, inst, carolKey); len(rows) != 0 {
53 t.Fatalf("reader's inbox: %+v", rows)
54 }
55 if out, _, _ := inst.ssh(t, bobKey, "", "repo", "show", "alice/app", "--json"); strings.Contains(out, `"watch":"watching"`) {
56 t.Fatalf("preference wrote a watch row: %s", out)
57 }
58
59 // The account page shows it on and turns it off.
60 bob := inst.login(t, bobKey)
61 set := inst.base() + "/settings"
62 if _, body := browserGet(t, bob, set); !strings.Contains(body, `name="watch" value="on" checked`) {
63 t.Fatalf("account page does not show watch on:\n%s", body)
64 }
65 if status, _ := browserPost(t, bob, set, url.Values{"field": {"notify-watch"}}); status != 200 {
66 t.Fatalf("settings post: %d", status)
67 }
68 if out, _, _ := inst.ssh(t, bobKey, "", "notifications", "settings", "show", "--json"); !strings.Contains(out, `"watch":false`) {
69 t.Fatalf("web toggle did not turn watch off: %s", out)
70 }
71 if _, errOut, code := inst.ssh(t, daveKey, "", "issue", "create", "alice/app", "--title", "'second'"); code != 0 {
72 t.Fatalf("second issue: %s", errOut)
73 }
74 if rows := notices(t, inst, bobKey); len(rows) != 1 {
75 t.Fatalf("inbox after watch off: %+v", rows)
76 }
77}