tinyrelayfile
tinyrelay/tinyclient/chat_activity_test.go/

tinyclient/chat_activity_test.go raw
1package tinyclient
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestChatActivityViewScopesDecisionsAndPreservesJobSummary(t *testing.T) {
9 actor := strings.Repeat("a", 64)
10 other := strings.Repeat("b", 64)
11 jobs := map[string]any{"items": []any{map[string]any{"id": strings.Repeat("1", 64), "requester": other, "status": "working", "content": "Indexing files"}}}
12 approvals := map[string]any{"items": []any{
13 map[string]any{"id": strings.Repeat("2", 64), "asker": other, "asked": []any{actor}, "subject": "Publish result", "state": "open", "kind": "4550"},
14 map[string]any{"id": strings.Repeat("3", 64), "asker": other, "asked": []any{other}, "subject": "Private request", "state": "open", "kind": "4550"},
15 }}
16 items := chatActivityView(jobs, approvals, actor, "/chat/activity", "general")
17 if len(items) != 2 {
18 t.Fatalf("got %d activity items, want job and addressed approval", len(items))
19 }
20 if items[0].Type != "job" || items[0].Status != "working" || items[0].Title != "Indexing files" {
21 t.Fatalf("unexpected job card: %#v", items[0])
22 }
23 if items[1].Type != "approval" || !items[1].CanDecide || items[1].ID != strings.Repeat("2", 64) {
24 t.Fatalf("unexpected approval card: %#v", items[1])
25 }
26}
27
28func TestChatActivityViewDisablesAnsweredApproval(t *testing.T) {
29 actor := strings.Repeat("a", 64)
30 approvals := map[string]any{"items": []any{map[string]any{"id": strings.Repeat("2", 64), "asker": actor, "asked": []any{actor}, "content": "Done", "state": "answered"}}}
31 items := chatActivityView(nil, approvals, actor, "/chat/activity", "general")
32 if len(items) != 1 || items[0].CanDecide {
33 t.Fatalf("answered approval remained actionable: %#v", items)
34 }
35}
36
37func TestChatActivityAskerCannotApproveOwnRequest(t *testing.T) {
38 actor := strings.Repeat("a", 64)
39 approvals := map[string]any{"items": []any{map[string]any{"id": strings.Repeat("2", 64), "asker": actor, "asked": []string{actor, strings.Repeat("b", 64)}, "state": "open"}}}
40 items := chatActivityView(nil, approvals, actor, "/chat/activity", "main")
41 if len(items) != 1 || items[0].CanDecide {
42 t.Fatalf("asker allowed to decide: %#v", items)
43 }
44}
45
46func TestChatActivityPreservesAnsweredQuestion(t *testing.T) {
47 actor := strings.Repeat("a", 64)
48 other := strings.Repeat("b", 64)
49 approvals := map[string]any{"items": []any{map[string]any{
50 "id": strings.Repeat("4", 64), "asker": other, "asked": []string{actor},
51 "type": "question", "subject": "Which preview?", "state": "answered",
52 "answer": map[string]any{"decision": "replied", "content": "Use the dark preview."},
53 }}}
54 items := chatActivityView(nil, approvals, actor, "/chat/activity", "general")
55 if len(items) != 1 || items[0].Answer != "Use the dark preview." || items[0].CanDecide {
56 t.Fatalf("answered question = %#v", items)
57 }
58}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs