oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package chat
2
3import (
4 "amadan.net/oficina/equipo/internal/wire"
5 "context"
6 "testing"
7)
8
9func TestRosterCardContext(t *testing.T) {
10 r := newMeteredRig(t)
11 ctx := context.Background()
12 for _, p := range []projectRecord{{ID: "p_old", Title: "Earlier", TitleSet: true, Repo: "amadan.net/one/old"}, {ID: "p_current", Title: "Woodstar", TitleSet: true, Repo: "amadan.net/one/current", State: "removed"}, {ID: "p_create", Title: "Create", Repo: "amadan.net/oficina/equipo"}} {
13 if err := r.s.db.G.Create(&p).Error; err != nil {
14 t.Fatal(err)
15 }
16 }
17 if err := r.s.db.G.Create(&taskRecord{ID: "tk_context", ProjectID: "p_current", Title: "Improve sign-in", Creator: hkOwner}).Error; err != nil {
18 t.Fatal(err)
19 }
20 for _, c := range []cardRecord{
21 {ID: "c_task", Person: hkOwner, TaskID: "tk_context", ProjectID: "p_old", Kind: wire.CardQuestion},
22 {ID: "c_project", Person: hkOwner, ProjectID: "p_old", Kind: wire.CardProject},
23 {ID: "c_global", Person: hkOwner, Kind: wire.CardQuestion},
24 {ID: "c_other", Person: hkMember, TaskID: "tk_context", Kind: wire.CardQuestion},
25 {ID: "c_missing", Person: hkOwner, TaskID: "gone", ProjectID: "p_old", Kind: wire.CardQuestion},
26 {ID: "c_create", Person: hkOwner, ProjectID: "p_create", Kind: wire.CardProject},
27 } {
28 if err := r.s.db.G.Create(&c).Error; err != nil {
29 t.Fatal(err)
30 }
31 }
32 got, err := r.s.CardPresentations(ctx, hkOwner, []string{"c_task", "c_project", "c_global", "c_other", "c_missing", "c_create"})
33 if err != nil {
34 t.Fatal(err)
35 }
36 if c := got["c_task"].Context; c.ProjectID != "p_current" || c.ProjectTitle != "Woodstar" || c.TaskTitle != "Improve sign-in" {
37 t.Fatalf("task context: %+v", c)
38 }
39 if c := got["c_project"].Context; c.ProjectTitle != "Earlier" || c.TaskTitle != "" {
40 t.Fatalf("project-only context: %+v", c)
41 }
42 if c := got["c_global"].Context; c != (CardContext{}) {
43 t.Fatalf("invented context: %+v", c)
44 }
45 if _, ok := got["c_other"]; ok {
46 t.Fatal("other person's card exposed")
47 }
48 // A title Equipo stored itself (#49) shows as the repository's name.
49 if c := got["c_create"].Context; c.ProjectTitle != "Equipo" {
50 t.Fatalf("stored title shown: %+v", c)
51 }
52 if c := got["c_missing"].Context; c.ProjectTitle != "Earlier" || c.TaskTitle != "" {
53 t.Fatalf("missing task failed graceful context: %+v", c)
54 }
55}
56