forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers_test.go
109 lines (93 loc) · 3.45 KB
/
handlers_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
107
108
109
package slacktest
import (
"testing"
slack "github.com/nlopes/slack"
"github.com/stretchr/testify/assert"
)
func TestAuthTestHandler(t *testing.T) {
s := NewTestServer()
go s.Start()
client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL()))
user, err := client.AuthTest()
assert.NoError(t, err, "should not error out")
assert.Equal(t, defaultTeamName, user.Team, "user ID should be correct")
assert.Equal(t, defaultTeamID, user.TeamID, "user ID should be correct")
assert.Equal(t, defaultNonBotUserID, user.UserID, "user ID should be correct")
assert.Equal(t, defaultNonBotUserName, user.User, "user ID should be correct")
}
func TestPostMessageHandler(t *testing.T) {
s := NewTestServer()
go s.Start()
client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL()))
channel, tstamp, err := client.PostMessage("foo", slack.MsgOptionText("some text", false), slack.MsgOptionPostMessageParameters(slack.PostMessageParameters{}))
assert.NoError(t, err, "should not error out")
assert.Equal(t, "foo", channel, "channel should be correct")
assert.NotEmpty(t, tstamp, "timestamp should not be empty")
}
func TestServerListChannels(t *testing.T) {
s := NewTestServer()
go s.Start()
client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL()))
channels, err := client.GetChannels(true)
assert.NoError(t, err)
assert.Len(t, channels, 2)
assert.Equal(t, "C024BE91L", channels[0].ID)
assert.Equal(t, "C024BE92L", channels[1].ID)
for _, channel := range channels {
assert.Equal(t, "W012A3CDE", channel.Creator)
}
}
func TestUserInfoHandler(t *testing.T) {
s := NewTestServer()
go s.Start()
client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL()))
user, err := client.GetUserInfo("123456")
assert.NoError(t, err)
assert.Equal(t, "W012A3CDE", user.ID)
assert.Equal(t, "spengler", user.Name)
assert.True(t, user.IsAdmin)
}
func TestBotInfoHandler(t *testing.T) {
s := NewTestServer()
go s.Start()
client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL()))
bot, err := client.GetBotInfo(s.BotID)
assert.NoError(t, err)
assert.Equal(t, s.BotID, bot.ID)
assert.Equal(t, s.BotName, bot.Name)
assert.False(t, bot.Deleted)
}
func TestListGroupsHandler(t *testing.T) {
s := NewTestServer()
go s.Start()
client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL()))
groups, err := client.GetGroups(true)
assert.NoError(t, err)
if !assert.Len(t, groups, 1, "should have one group") {
t.FailNow()
}
mygroup := groups[0]
assert.Equal(t, "G024BE91L", mygroup.ID, "id should match")
assert.Equal(t, "secretplans", mygroup.Name, "name should match")
assert.True(t, mygroup.IsGroup, "should be a group")
}
func TestListChannelsHandler(t *testing.T) {
s := NewTestServer()
go s.Start()
client := slack.New("ABCDEFG", slack.OptionAPIURL(s.GetAPIURL()))
channels, err := client.GetChannels(true)
assert.NoError(t, err)
if !assert.Len(t, channels, 2, "should have two channels") {
t.FailNow()
}
generalChan := channels[0]
otherChan := channels[1]
assert.Equal(t, "C024BE91L", generalChan.ID, "id should match")
assert.Equal(t, "general", generalChan.Name, "name should match")
assert.Equal(t, "Fun times", generalChan.Topic.Value)
assert.True(t, generalChan.IsMember, "should be in channel")
assert.Equal(t, "C024BE92L", otherChan.ID, "id should match")
assert.Equal(t, "bot-playground", otherChan.Name, "name should match")
assert.Equal(t, "Fun times", otherChan.Topic.Value)
assert.True(t, otherChan.IsMember, "should be in channel")
}