-
Notifications
You must be signed in to change notification settings - Fork 6
/
chat_service_test.go
59 lines (47 loc) · 1.25 KB
/
chat_service_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
package karmabot
import (
"github.com/nlopes/slack"
)
type TestChatService struct {
IncomingEvents chan slack.RTMEvent
SentMessages []*slack.OutgoingMessage
id int
}
func newTestChatService() ChatService {
return &TestChatService{}
}
func (t *TestChatService) IncomingEventsChan() chan slack.RTMEvent {
return t.IncomingEvents
}
func (t *TestChatService) OpenIMChannel(user string) (bool, bool, string, error) {
return true, true, user, nil
}
func (t *TestChatService) GetUserInfo(user string) (*slack.User, error) {
return &slack.User{
ID: user,
Name: user,
}, nil
}
func (t *TestChatService) NewOutgoingMessage(text string, channel string, options ...slack.RTMsgOption) *slack.OutgoingMessage {
t.id++
return &slack.OutgoingMessage{
ID: t.id,
Type: "message",
Channel: channel,
Text: text,
}
}
func (t *TestChatService) SendMessage(m *slack.OutgoingMessage) {
t.SentMessages = append(t.SentMessages, m)
}
func (t *TestChatService) PostEphemeral(channelID, userID string, options ...slack.MsgOption) (string, error) {
// run options
_, values, _ := slack.UnsafeApplyMsgOptions("", "", options...)
message := values.Get("text")
t.SendMessage(
t.NewOutgoingMessage(
message, "user",
),
)
return "", nil
}