internal/store/ownerevents_test.go
71 lines · 1923 bytes
1package store
2
3import "testing"
4
5// The profile's activity log has to count what the graph over it counts.
6// For a user that is what they did, wherever they did it — not what
7// happened on the repositories they happen to own.
8func TestUserPublicEventsKeyOnTheActor(t *testing.T) {
9 s := open(t)
10 if err := s.MigrateUp(); err != nil {
11 t.Fatal(err)
12 }
13
14 alice, err := s.CreateUser("alice", false)
15 if err != nil {
16 t.Fatal(err)
17 }
18 bob, err := s.CreateUser("bob", false)
19 if err != nil {
20 t.Fatal(err)
21 }
22 // alice owns one public and one private repository; bob owns one.
23 aliceRepo, err := s.CreateRepo("user", alice, "app", "public")
24 if err != nil {
25 t.Fatal(err)
26 }
27 secret, err := s.CreateRepo("user", alice, "secret", "private")
28 if err != nil {
29 t.Fatal(err)
30 }
31 bobRepo, err := s.CreateRepo("user", bob, "tool", "public")
32 if err != nil {
33 t.Fatal(err)
34 }
35
36 for _, e := range []struct {
37 repo, actor int64
38 kind string
39 }{
40 {aliceRepo, alice, "issue.opened"}, // hers, on her repo
41 {bobRepo, alice, "issue.opened"}, // hers, on someone else's
42 {aliceRepo, bob, "issue.opened"}, // his, on her repo
43 {secret, alice, "issue.opened"}, // hers, but private
44 {aliceRepo, alice, "push"}, // pushes never appear
45 } {
46 if err := s.RecordEvent(e.repo, e.actor, e.kind, "{}"); err != nil {
47 t.Fatal(err)
48 }
49 }
50
51 got, err := s.UserPublicEvents(alice, 10)
52 if err != nil {
53 t.Fatal(err)
54 }
55 if len(got) != 2 {
56 t.Fatalf("want alice's two public events, got %d: %+v", len(got), got)
57 }
58 // Newest first, and both are hers.
59 if got[0].RepoPath != "bob/tool" || got[1].RepoPath != "alice/app" {
60 t.Errorf("wrong rows or order: %+v", got)
61 }
62 for _, e := range got {
63 if e.Actor != "alice" {
64 t.Errorf("an event alice did not do: %+v", e)
65 }
66 }
67
68 if got, err := s.UserPublicEvents(alice, 1); err != nil || len(got) != 1 {
69 t.Fatalf("limit not applied: %d %v", len(got), err)
70 }
71}