-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
assistant_test.go
86 lines (63 loc) · 1.98 KB
/
assistant_test.go
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
package slack
import (
"encoding/json"
"net/http"
"testing"
)
func TestAssistantThreadsSuggestedPrompts(t *testing.T) {
http.HandleFunc("/assistant.threads.setSuggestedPrompts", okJSONHandler)
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
params := AssistantThreadsSetSuggestedPromptsParameters{
ChannelID: "CXXXXXXXX",
ThreadTS: "1234567890.123456",
}
params.AddPrompt("title1", "message1")
params.AddPrompt("title2", "message2")
err := api.SetAssistantThreadsSuggestedPrompts(params)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
}
func TestSetAssistantThreadsStatus(t *testing.T) {
http.HandleFunc("/assistant.threads.setStatus", okJSONHandler)
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
params := AssistantThreadsSetStatusParameters{
ChannelID: "CXXXXXXXX",
ThreadTS: "1234567890.123456",
Status: "updated status",
}
err := api.SetAssistantThreadsStatus(params)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
}
func assistantThreadsTitleHandler(rw http.ResponseWriter, r *http.Request) {
channelID := r.FormValue("channel_id")
threadTS := r.FormValue("thread_ts")
title := r.FormValue("title")
rw.Header().Set("Content-Type", "application/json")
if channelID != "" && threadTS != "" && title != "" {
resp, _ := json.Marshal(&addBookmarkResponse{
SlackResponse: SlackResponse{Ok: true},
})
rw.Write(resp)
} else {
rw.Write([]byte(`{ "ok": false, "error": "errored" }`))
}
}
func TestSetAssistantThreadsTitle(t *testing.T) {
http.HandleFunc("/assistant.threads.setTitle", assistantThreadsTitleHandler)
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
params := AssistantThreadsSetTitleParameters{
ChannelID: "CXXXXXXXX",
ThreadTS: "1234567890.123456",
Title: "updated title",
}
err := api.SetAssistantThreadsTitle(params)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
}