-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquestion_test.go
More file actions
201 lines (165 loc) · 4.46 KB
/
question_test.go
File metadata and controls
201 lines (165 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package slagent
import (
"strings"
"testing"
)
func TestPostPromptAddsReactions(t *testing.T) {
mock := newMockSlack()
defer mock.close()
thread := NewThread(mock.client(), "C_TEST", WithOwner("U_OWNER"))
thread.Start("test")
reactions := []string{"one", "two", "three", "x"}
msgTS, err := thread.PostPrompt("pick one", reactions)
if err != nil {
t.Fatal(err)
}
// All reactions should be pre-added for session tokens
for _, r := range reactions {
mock.mu.Lock()
users := mock.reactions[msgTS][r]
mock.mu.Unlock()
if !users["U_OWNER"] {
t.Errorf("reaction %q should be pre-added, got users: %v", r, users)
}
}
}
func TestGetReactionsReturnsState(t *testing.T) {
mock := newMockSlack()
defer mock.close()
thread := NewThread(mock.client(), "C_TEST", WithOwner("U_OWNER"))
thread.Start("test")
reactions := []string{"one", "two", "x"}
msgTS, err := thread.PostPrompt("pick", reactions)
if err != nil {
t.Fatal(err)
}
items, err := thread.GetReactions(msgTS)
if err != nil {
t.Fatal(err)
}
// Should have all 3 reactions with owner
found := make(map[string]bool)
for _, item := range items {
found[item.Name] = true
}
for _, r := range reactions {
if !found[r] {
t.Errorf("GetReactions missing %q", r)
}
}
}
func TestGetReactionsAfterOwnerClick(t *testing.T) {
mock := newMockSlack()
defer mock.close()
thread := NewThread(mock.client(), "C_TEST", WithOwner("U_OWNER"))
thread.Start("test")
reactions := []string{"one", "two", "x"}
msgTS, err := thread.PostPrompt("pick", reactions)
if err != nil {
t.Fatal(err)
}
// Simulate owner clicking "two" (removes it)
mock.simulateOwnerClick(msgTS, "two")
items, err := thread.GetReactions(msgTS)
if err != nil {
t.Fatal(err)
}
// "two" should be gone (or empty users), "one" and "x" should still have owner
for _, item := range items {
if item.Name == "two" {
for _, u := range item.Users {
if u == "U_OWNER" {
t.Error("owner should not be on 'two' after click")
}
}
}
}
}
func TestAddReactionRestoresAfterClick(t *testing.T) {
mock := newMockSlack()
defer mock.close()
thread := NewThread(mock.client(), "C_TEST", WithOwner("U_OWNER"))
thread.Start("test")
reactions := []string{"one", "two"}
msgTS, err := thread.PostPrompt("pick", reactions)
if err != nil {
t.Fatal(err)
}
// Owner clicks "one"
mock.simulateOwnerClick(msgTS, "one")
// Re-add it
thread.AddReaction(msgTS, "one")
// Owner should be back on "one"
mock.mu.Lock()
hasOwner := mock.reactions[msgTS]["one"]["U_OWNER"]
mock.mu.Unlock()
if !hasOwner {
t.Error("AddReaction should restore owner on the reaction")
}
}
func TestRemoveAllReactions(t *testing.T) {
mock := newMockSlack()
defer mock.close()
thread := NewThread(mock.client(), "C_TEST", WithOwner("U_OWNER"))
thread.Start("test")
reactions := []string{"one", "two", "x"}
msgTS, err := thread.PostPrompt("pick", reactions)
if err != nil {
t.Fatal(err)
}
thread.RemoveAllReactions(msgTS, reactions)
// All reactions should be removed
items, err := thread.GetReactions(msgTS)
if err != nil {
t.Fatal(err)
}
for _, item := range items {
for _, u := range item.Users {
if u == "U_OWNER" {
t.Errorf("reaction %q should be removed, still has owner", item.Name)
}
}
}
}
func TestUpdateMessageChangesText(t *testing.T) {
mock := newMockSlack()
defer mock.close()
thread := NewThread(mock.client(), "C_TEST", WithOwner("U_OWNER"))
thread.Start("test")
msgTS, err := thread.PostPrompt("original text", []string{"one"})
if err != nil {
t.Fatal(err)
}
// Update the message
thread.UpdateMessage(msgTS, "updated with 👉")
// Verify the message was updated
msgs := mock.activeMessages()
for _, msg := range msgs {
if msg.TS == msgTS {
if !strings.Contains(msg.blockText(), "👉") {
t.Errorf("message should be updated, got: %q", msg.blockText())
}
return
}
}
t.Error("message not found after update")
}
func TestThinkingEmoji(t *testing.T) {
mock := newMockSlack()
defer mock.close()
thread := NewThread(mock.client(), "C_TEST",
WithOwner("U_OWNER"),
WithThinkingEmoji(":claude-thinking:"),
)
if thread.ThinkingEmoji() != ":claude-thinking:" {
t.Errorf("ThinkingEmoji = %q, want :claude-thinking:", thread.ThinkingEmoji())
}
}
func TestThinkingEmojiDefault(t *testing.T) {
mock := newMockSlack()
defer mock.close()
thread := NewThread(mock.client(), "C_TEST")
if thread.ThinkingEmoji() != ":claude:" {
t.Errorf("ThinkingEmoji = %q, want :claude:", thread.ThinkingEmoji())
}
}