-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwkteam_api_test.go
173 lines (159 loc) · 4.1 KB
/
wkteam_api_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package wkteam
import (
"github.com/stretchr/testify/require"
"github.com/suboat/go-contrib"
"fmt"
"testing"
"time"
)
var (
// 单元测试读取的配置信息, 账号信息在内
testConfig = "config.test.yaml"
//
testGroupID = "18217585821@chatroom" // 测试群号
testFriendUID = "golang" // 测试好友微信号
testFriendAlias = "这是一个足够长的测试备注名" // 测试好友微信号
)
// 读取测试配置文件
func testConfigRead() {
if len(testConfig) == 0 {
return
}
var err error
if err = contrib.PubConfigRead(testConfig, Settings, Settings); err != nil {
panic(fmt.Errorf(`配置文件读取失败:%s, err:%v`, testConfig, err))
} else if err = Settings.Valid(); err != nil {
panic(fmt.Errorf(`配置文件非法:%s, err:%v`, testConfig, err))
}
if err = Settings.Save(nil); err != nil {
panic(fmt.Errorf(`配置文件更新失败:%s, err:%v`, testConfig, err))
}
testConfig = ""
return
}
// 获取账号信息
func Test_GetAgent(t *testing.T) {
testConfigRead()
as := require.New(t)
api := &WkTeam{}
d, err := api.GetAgent()
as.Nil(err)
t.Log(PubJSON(d))
}
// 获取群列表
func Test_GetGroups(t *testing.T) {
testConfigRead()
as := require.New(t)
api := NewWkTeam(nil)
d, err := api.GetGroups(nil)
as.Nil(err)
t.Log(PubJSON(d))
}
// 取群消息
func Test_GetMsgGroup(t *testing.T) {
testConfigRead()
as := require.New(t)
api := NewWkTeam(nil)
query := &Query{Limit: 30, Page: 0}
d, err := api.GetMsgGroup(testGroupID, query)
as.Nil(err)
// 调试信息
for _i, _d := range d {
api.Log.Infof("#%d %s -> %s(%s): %s", _i+1, _d.Time, _d.Uid, _d.GetName(), _d.Content)
if _i == len(d)-1 {
api.Log.Info(PubJSON(_d))
}
}
api.Log.Infof("获取到群消息 %d/%d", len(d), query.Total)
}
// 取某个时间点后的所有群聊消息
func Test_GetMsgGroupSince(t *testing.T) {
testConfigRead()
as := require.New(t)
api := NewWkTeam(nil)
since := time.Now().Add(-time.Hour * 4)
d, err := api.GetMsgGroupSince(testGroupID, since)
as.Nil(err)
// 调试信息
for _i, _d := range d {
api.Log.Infof("#%d %s -> %s(%s): %s", _i+1, _d.Time, _d.Uid, _d.GetName(), _d.Content)
if _i == len(d)-1 {
api.Log.Info(PubJSON(_d))
}
}
api.Log.Infof("获取到群消息 %d since: %s", len(d), since)
}
// 取好友单聊消息
func Test_GetMsgUser(t *testing.T) {
testConfigRead()
as := require.New(t)
api := NewWkTeam(nil)
query := &Query{Limit: 30, Page: 0}
d, err := api.GetMsgUser(testFriendUID, query)
as.Nil(err)
// 调试信息
for _i, _d := range d {
api.Log.Infof("#%d %s %s -> %s : %s", _i+1, _d.Time, _d.GetFromName(), _d.GetToName(), _d.Content)
if _i == len(d)-1 {
api.Log.Info(PubJSON(_d))
}
}
api.Log.Infof("获取到的好友消息 %d/%d", len(d), query.Total)
}
// 取某个时间点后的好友单聊消息
func Test_GetMsgUserSince(t *testing.T) {
testConfigRead()
as := require.New(t)
api := NewWkTeam(nil)
since := time.Now().Add(-time.Hour * 4)
d, err := api.GetMsgUserSince(testFriendUID, since)
as.Nil(err)
// 调试信息
for _i, _d := range d {
api.Log.Infof("#%d %s %s -> %s : %s", _i+1, _d.Time, _d.GetFromName(), _d.GetToName(), _d.Content)
if _i == len(d)-1 {
api.Log.Info(PubJSON(_d))
}
}
api.Log.Infof("获取到的好友消息 %d since: %s", len(d), since)
}
// 同意好友添加申请
func Test_PassAddFriend(t *testing.T) {
testConfigRead()
as := require.New(t)
api := NewWkTeam(nil)
d, err := api.PassAddFriend(testFriendUID)
as.Nil(err)
t.Log(d)
return
}
// 备注好友
func Test_RemarkFriend(t *testing.T) {
testConfigRead()
as := require.New(t)
api := NewWkTeam(nil)
d, err := api.RemarkFriend(testFriendUID, testFriendAlias)
as.Nil(err)
t.Log(d)
return
}
// 获取一个群的详细消息
func Test_GetGroupInfo(t *testing.T) {
testConfigRead()
as := require.New(t)
api := NewWkTeam(nil)
d, err := api.GetGroupInfo("群的number")
as.Nil(err)
t.Log(d)
return
}
// 获取一个群的详细消息
func Test_GetUserInfo(t *testing.T) {
testConfigRead()
as := require.New(t)
api := NewWkTeam(nil)
d, err := api.GetUserInfo("微信号")
as.Nil(err)
t.Log(d)
return
}