-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathchat_test.go
106 lines (94 loc) · 2.48 KB
/
chat_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package slack_test
import (
"context"
"testing"
"github.com/lestrrat-go/slack"
"github.com/lestrrat-go/slack/objects"
"github.com/stretchr/testify/assert"
)
// Test message create, update, delete
func TestChatMessage(t *testing.T) {
if !requireSlackToken(t) || !requireDMUser(t) {
return
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c := slack.New(slackToken)
t.Run("basic usage", func(t *testing.T) {
res, err := c.Chat().PostMessage(testDmUser).Text("hello").Do(ctx)
if !assert.NoError(t, err, "Chat.PostMessage failed") {
return
}
t.Logf("%#v", res)
/*
res, err = c.Chat().Update(ctx, res.Channel, res.Timestamp, "hello, world!")
if !assert.NoError(t, err, "Chat.Update failed") {
return
}
t.Logf("%#v", res)
res, err = c.Chat().Delete(ctx, res.Channel, res.Timestamp)
if !assert.NoError(t, err, "Chat.Delete failed") {
return
}
t.Logf("%#v", res)
*/
})
t.Run("buttons", func(t *testing.T) {
var attachment objects.Attachment
attachment.CallbackID = "wopr_game"
attachment.Color = "#3AA3E3"
attachment.Fallback = "You are unable to choose a game"
attachment.Text = "Choose a game to play"
attachment.Actions.
Append(&objects.Action{
Name: "game",
Text: "Chess",
Type: objects.ButtonActionType,
Value: "chess",
}).
Append(&objects.Action{
Name: "game",
Text: "Falken's Maze",
Type: objects.ButtonActionType,
Value: "maze",
}).
Append(&objects.Action{
Name: "game",
Text: "Thermonuclear War",
Style: "danger",
Type: objects.ButtonActionType,
Value: "war",
Confirm: &objects.Confirmation{
Title: "Are you sure?",
Text: "Wouldn't you prefer a good game of chess?",
OkText: "Yes",
DismissText: "No",
},
})
res, err := c.Chat().PostMessage(testDmUser).
AsUser(true).
Attachment(&attachment).
Text("Would you like to play a game?").
Do(ctx)
if !assert.NoError(t, err, "Chat.PostMessage failed") {
return
}
t.Logf("%#v", res)
})
}
// MeMessages require chat:write:user, so I think I'm going to punt it
/*
func TestChatMeMessage(t *testing.T) {
if !requireSlackToken(t) || !requireDMUser(t) || !requireRealUser(t) {
return
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c := slack.New(slackToken)
res, err := c.Chat().MeMessage(ctx, testDmUser, "hello")
if !assert.NoError(t, err, "Chat.MeMessage failed") {
return
}
t.Logf("%#v", res)
}
*/