forked from sbstjn/hanu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_test.go
86 lines (69 loc) · 2.15 KB
/
message_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 hanu
import "testing"
func TestMessage(t *testing.T) {
msg := Message{
ID: 0,
UserID: "test",
Type: "message",
Message: "text",
}
if msg.User() != "test" {
t.Errorf("User() should be \"test\"")
}
if msg.Text() != "text" {
t.Errorf("Text() should be \"test\", is \"%s\"", msg.Text())
}
if !msg.IsMessage() {
t.Errorf("IsMessage() must be true")
}
if msg.IsDirectMessage() {
t.Errorf("msg.IsDirectMessage() must be false")
}
if msg.IsMentionFor("") {
t.Errorf("msg.IsMentionFor() must be false")
}
if msg.IsRelevantFor("user") {
t.Errorf("msg.IsRelevantFor() must be true")
}
}
func TestHelpMessage(t *testing.T) {
msg := Message{}
msg.SetText("help")
if !msg.IsHelpRequest() {
t.Errorf("msg.IsHelpRequest() must be true")
}
}
func TestStripMention(t *testing.T) {
msg := Message{}
msg.SetText("<@test> help")
msg.Message = msg.StripMention("test")
if msg.Text() != "help" {
t.Errorf("msg.Text must be 'help', is \"%s\"", msg.Text())
}
}
func TestStripFormatting(t *testing.T) {
var data = []struct {
in string
out string
}{
{"how are you?", "how are you?"},
{"<@test> how are you?", "how are you?"},
{"<@test> Hi <http://example.com|example.com> test <https://lorem.ipsum|ipsum.com> fail", "Hi example.com test ipsum.com fail"},
{"<@test> Hi <http://example.com|example.com> test <https://lorem.ipsum> fail", "Hi example.com test https://lorem.ipsum fail"},
{"<@test> Hi <slackbot://[email protected]>", "Hi slackbot://[email protected]"},
{"<@test> Hi <slackbot://[email protected]|label>", "Hi label"},
{"<@U02UNKSJ1> is not changed", "<@U02UNKSJ1> is not changed"},
{"<#C0C9MF8AK|channel> is not changed", "<#C0C9MF8AK|channel> is not changed"},
{"<!subteam^S2N709QUT|@team> is not changed", "<!subteam^S2N709QUT|@team> is not changed"},
{"asdas <http://google.com> asdasd", "asdas http://google.com asdasd"},
}
for _, set := range data {
msg := Message{}
msg.SetText(set.in)
msg.Message = msg.StripMention("test")
msg.Message = msg.StripLinkMarkup()
if msg.Text() != set.out {
t.Errorf("Failed to strip markup: \n Got: %s\n Expected: %s", msg.Text(), set.out)
}
}
}