internal/control/issue_test.go

v1.36.0
gitbay/internal/control/issue_test.go history · blame · raw

66 lines · 2305 bytes

 1package control
 2
 3import "testing"
 4
 5func TestIssueAssignNotifiesTheAssignee(t *testing.T) {
 6	c, repo, bob := testRepoWithWatcher(t)
 7
 8	if code := runIssueAssign(c, []string{repo.Path(), "1", "--add", "bob"}); code != 0 {
 9		t.Fatalf("exit %d", code)
10	}
11	rows, _ := c.Store.Inbox(bob, false, 20, 0)
12	if len(rows) != 1 || rows[0].Summary != "assigned you to #1" {
13		t.Fatalf("got %+v", rows)
14	}
15}
16
17// The spec files a notice for each account newly added. SetIssueAssignee
18// inserts ON CONFLICT DO NOTHING and reports nothing either way, so a
19// client reconciling an assignee list by re-sending the whole set would
20// file, mail and push a row on every save.
21func TestIssueAssignDoesNotRenotifyAnExistingAssignee(t *testing.T) {
22	c, repo, bob := testRepoWithWatcher(t)
23	c.Store.AddPushDevice(bob, "tok-b", "iphone")
24
25	if code := runIssueAssign(c, []string{repo.Path(), "1", "--add", "bob"}); code != 0 {
26		t.Fatalf("exit %d", code)
27	}
28	if code := runIssueAssign(c, []string{repo.Path(), "1", "--add", "bob"}); code != 0 {
29		t.Fatalf("exit %d", code)
30	}
31
32	rows, _ := c.Store.Inbox(bob, false, 20, 0)
33	if len(rows) != 1 {
34		t.Fatalf("filed %d rows for one assignment: %+v", len(rows), rows)
35	}
36	if due, _ := c.Store.DuePush(20); len(due) != 1 {
37		t.Fatalf("queued %d pushes for one assignment", len(due))
38	}
39	// The second call still succeeds and still reports the assignee.
40	updated, err := c.Store.IssueByNumber(repo.ID, 1)
41	if err != nil {
42		t.Fatal(err)
43	}
44	if len(updated.Assignees) != 1 || updated.Assignees[0] != "bob" {
45		t.Fatalf("assignees: %+v", updated.Assignees)
46	}
47}
48
49func TestIssueAssignIsSilentForTheActorAndForRemovals(t *testing.T) {
50	c, repo, bob := testRepoWithWatcher(t)
51
52	// Assigning yourself announces nothing: notify drops the actor.
53	runIssueAssign(c, []string{repo.Path(), "1", "--add", "alice"})
54	if rows, _ := c.Store.Inbox(c.User.ID, false, 20, 0); len(rows) != 0 {
55		t.Fatalf("self-assignment notified: %+v", rows)
56	}
57
58	// Unassigning files nothing.
59	runIssueAssign(c, []string{repo.Path(), "1", "--add", "bob"})
60	before, _ := c.Store.Inbox(bob, false, 20, 0)
61	runIssueAssign(c, []string{repo.Path(), "1", "--remove", "bob"})
62	after, _ := c.Store.Inbox(bob, false, 20, 0)
63	if len(after) != len(before) {
64		t.Fatalf("removal filed a row: %d then %d", len(before), len(after))
65	}
66}