forked from go-lark/lark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_chat_test.go
125 lines (114 loc) · 3.33 KB
/
api_chat_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package lark
import (
"fmt"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestChatInfo(t *testing.T) {
bot.WithUserIDType(UIDOpenID)
assert.Equal(t, UIDOpenID, bot.userIDType)
resp, err := bot.GetChat(testGroupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.Equal(t, "go-lark-ci", resp.Data.Name)
assert.Equal(t, "group", resp.Data.ChatMode)
assert.Equal(t, testUserOpenID, resp.Data.OwnerID)
t.Log(resp.Data)
}
}
func TestChatList(t *testing.T) {
bot.WithUserIDType(UIDOpenID)
assert.Equal(t, UIDOpenID, bot.userIDType)
resp, err := bot.ListChat("ByCreateTimeAsc", "", 10)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.NotEmpty(t, resp.Data.Items)
t.Log(resp.Data.Items[0])
}
}
func TestChatSearch(t *testing.T) {
bot.WithUserIDType(UIDOpenID)
assert.Equal(t, UIDOpenID, bot.userIDType)
resp, err := bot.SearchChat("go-lark", "", 10)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
if assert.NotEmpty(t, resp.Data.Items) {
for _, item := range resp.Data.Items {
if !strings.Contains(item.Name, "go-lark") {
t.Error(item.Name, "does not contain go-lark")
}
}
}
t.Log(resp.Data.Items)
}
}
func TestChatCRUD(t *testing.T) {
bot.WithUserIDType(UIDOpenID)
resp, err := bot.CreateChat(CreateChatRequest{
Name: fmt.Sprintf("go-lark-ci-%d", time.Now().Unix()),
ChatMode: "group",
ChatType: "public",
})
if assert.NoError(t, err) {
chatID := resp.Data.ChatID
assert.NotEmpty(t, chatID)
upResp, err := bot.UpdateChat(chatID, UpdateChatRequest{
Description: "new description",
})
t.Log(upResp)
if assert.NoError(t, err) {
getResp, err := bot.GetChat(chatID)
if assert.NoError(t, err) {
assert.Equal(t, "new description", getResp.Data.Description)
// join chat
joinResp, err := bot.JoinChat(chatID)
assert.Zero(t, joinResp.Code)
assert.NoError(t, err)
// add chat member
addMemberResp, err := bot.AddChatMember(chatID, []string{testUserOpenID})
if assert.NoError(t, err) {
assert.Equal(t, 0, addMemberResp.Code)
assert.Empty(t, addMemberResp.Data.InvalidIDList)
}
// remove chat member
removeMemberResp, err := bot.RemoveChatMember(chatID, []string{testUserOpenID})
if assert.NoError(t, err) {
assert.Equal(t, 0, removeMemberResp.Code)
assert.Empty(t, removeMemberResp.Data.InvalidIDList)
}
// delete
_, err = bot.DeleteChat(chatID)
assert.NoError(t, err)
}
}
}
}
func TestIsInChat(t *testing.T) {
resp, err := bot.IsInChat(testGroupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.True(t, resp.Data.IsInChat)
}
}
func TestGetChatMembers(t *testing.T) {
bot.WithUserIDType(UIDOpenID)
resp, err := bot.GetChatMembers(testGroupChatID, "", 1)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.NotEmpty(t, resp.Data.Items)
assert.Empty(t, resp.Data.PageToken)
assert.NotEmpty(t, resp.Data.MemberTotal)
assert.False(t, resp.Data.HasMore)
}
}
func TestChatTopNotice(t *testing.T) {
resp, err := bot.PostText("group notice", WithChatID(testGroupChatID))
if assert.NoError(t, err) {
setResp, _ := bot.SetTopNotice(testGroupChatID, "2", resp.Data.MessageID)
assert.Equal(t, 0, setResp.Code)
delResp, _ := bot.DeleteTopNotice(testGroupChatID)
assert.Equal(t, 0, delResp.Code)
}
}