forked from BeepBoopHQ/go-slackbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_test.go
104 lines (77 loc) · 2.39 KB
/
utils_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
package slackbot
import (
"testing"
"github.com/slack-go/slack"
"github.com/stretchr/testify/assert"
)
func TestStripDirectMention(t *testing.T) {
assert := assert.New(t)
pairs := []string{
"a message", "a message",
" space", " space",
"<@USOMEUSER> I 😍 u", "I 😍 u",
"<@USOMEUSER> space", "space",
"<@USOMEUSER>: abc", "abc",
"<@USOMEUSER>: you <@USOMEUSER>", "you <@USOMEUSER>",
"space ", "space ",
}
for i := 0; i < len(pairs); {
assert.Equal(pairs[i+1], StripDirectMention(pairs[i]))
i += 2
}
}
func TestIsDirectMessage(t *testing.T) {
assert := assert.New(t)
msg := &slack.MessageEvent{}
msg.Channel = "DABCDEF"
assert.True(true, IsDirectMessage(msg))
msg.Channel = " DABCDEF"
assert.False(IsDirectMessage(msg))
msg.Channel = "UABCDEF"
assert.False(IsDirectMessage(msg))
msg.Channel = ""
assert.False(IsDirectMessage(msg))
}
func TestIsDirectMention(t *testing.T) {
assert := assert.New(t)
msg := &slack.MessageEvent{}
userID := "U12345"
msg.Text = "<@" + userID + "> some message"
assert.True(true, IsDirectMention(msg, userID))
msg.Text = " <@" + userID + "> some othermessage"
assert.False(IsDirectMention(msg, userID))
msg.Text = "<@" + userID + "> some longer message <@MENTION> message "
assert.True(IsDirectMention(msg, userID))
msg.Text = ""
assert.False(IsDirectMention(msg, userID))
msg.Text = " "
assert.False(IsDirectMention(msg, userID))
}
func TestWhoMentioned(t *testing.T) {
assert := assert.New(t)
msg := &slack.MessageEvent{}
msg.Text = "<@U123456> hi there <@UABCDEF>"
assert.Equal([]string{"U123456", "UABCDEF"}, WhoMentioned(msg))
msg.Text = "<@> <@DD <@U123456> hi there <@UABCDEF> LL"
assert.Equal([]string{"U123456", "UABCDEF"}, WhoMentioned(msg))
}
func TestIsMention(t *testing.T) {
assert := assert.New(t)
msg := &slack.MessageEvent{}
msg.Text = "<@U123456> hi there <@UABCDEF>"
assert.True(IsMention(msg))
msg.Text = "this is something"
assert.False(IsMention(msg))
}
func TestIsMentioned(t *testing.T) {
assert := assert.New(t)
msg := &slack.MessageEvent{}
msg.Text = "<@U123456> hi there <@UABCDEF>"
assert.True(IsMentioned(msg, "UABCDEF"))
msg.Text = "<@U123456> hi there <@UABCDEF>"
assert.False(IsMentioned(msg, "UABCDE"))
msg.Text = "<@U123456> hi there <@UABCDEF>"
assert.False(IsMentioned(msg, "UXXXXXX"))
msg.Text = "this is something"
assert.False(IsMentioned(msg, "UAAAAAA"))
}