forked from go-lark/lark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_group_test.go
86 lines (80 loc) · 2.09 KB
/
api_group_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 lark
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestGetGroupList(t *testing.T) {
resp, err := bot.GetGroupList(1, 10)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
t.Log(resp.Chats)
assert.NotEmpty(t, resp.Chats)
}
}
func TestGetGroupInfo(t *testing.T) {
resp, err := bot.GetGroupInfo(testGroupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.Equal(t, "go-lark-ci", resp.Data.Name)
assert.NotEmpty(t, resp.Data.Members)
}
}
func TestGroupCRUD(t *testing.T) {
// create group
createResp, err := bot.CreateGroup(
fmt.Sprintf("go-lark-ci group %d", time.Now().Unix()),
"group create",
[]string{testUserOpenID},
)
if assert.NoError(t, err) {
assert.Equal(t, 0, createResp.Code)
}
groupChatID := createResp.OpenChatID
// delete member
delResp, err := bot.DeleteGroupMember(groupChatID, []string{testUserOpenID})
if assert.NoError(t, err) {
assert.Equal(t, 0, delResp.Code)
}
// add member
addResp, err := bot.AddGroupMember(groupChatID, []string{testUserOpenID})
if assert.NoError(t, err) {
assert.Equal(t, 0, addResp.Code)
}
// delete again
delResp, err = bot.DeleteGroupMember(groupChatID, []string{testUserOpenID})
if assert.NoError(t, err) {
assert.Equal(t, 0, delResp.Code)
}
// add by user id
addByUserResp, err := bot.AddGroupMemberByUserID(groupChatID, []string{testUserID})
if assert.NoError(t, err) {
assert.Equal(t, 0, addByUserResp.Code)
}
// update info
updateResp, err := bot.UpdateGroupInfo(&UpdateGroupInfoReq{
OpenChatID: groupChatID,
Name: "test 1",
})
if assert.NoError(t, err) {
assert.Equal(t, 0, updateResp.Code)
}
// disband
disbandResp, err := bot.DisbandGroup(groupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, disbandResp.Code)
}
}
func TestBotAddRemove(t *testing.T) {
// rm bot
rmBotResp, err := bot.RemoveBotFromGroup(testGroupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, rmBotResp.Code)
}
// add bot
addBotResp, err := bot.AddBotToGroup(testGroupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, addBotResp.Code)
}
}