-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_test.go
200 lines (185 loc) · 7.59 KB
/
base_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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package dingtalk
import (
"os"
"testing"
)
func TestNewTextMessage(t *testing.T) {
textMessage := NewTextMessage("我就是我, @XXX 是不一样的烟火")
textMessage.At = NewAt(false)
textMessage.ToMessageMap()
}
func TestTextMessage_ToMessageMap(t *testing.T) {
textMessage := NewTextMessage("我就是我, @XXX 是不一样的烟火")
textMessage.At = NewAt(true)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
res, err := client.SendMessage(textMessage)
if err != nil {
t.Error("send message error", err)
}
if res.Success() {
t.Log("send message success")
} else {
t.Errorf("send message error: code: %d msg: %s", res.ErrorCode, res.ErrorMessage)
}
}
func TestNewLinkMessage(t *testing.T) {
linkMsg := NewLinkMessage("这个即将发布的新版本,创始人xx称它为红树林。而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是红树林",
"时代的火车向前开",
"https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI",
)
linkMsg.ToMessageMap()
}
func TestLinkMessage_ToMessageMap(t *testing.T) {
linkMsg := NewLinkMessage("这个即将发布的新版本,创始人xx称它为红树林。而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是红树林",
"时代的火车向前开",
"https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI",
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
res, err := client.SendMessage(linkMsg)
if err != nil {
t.Error("send message error", err)
}
if res.Success() {
t.Log("send message success")
} else {
t.Errorf("send message error: code: %d msg: %s", res.ErrorCode, res.ErrorMessage)
}
}
func TestNewMarkdownMessage(t *testing.T) {
markdownMsg := NewMarkdownMessage("杭州天气", "#### 杭州天气 @150XXXXXXXX \n > 9度,西北风1级,空气良89,相对温度73%\n > ![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)\n > ###### 10点20分发布 [天气](https://www.dingtalk.com) \n")
markdownMsg.ToMessageMap()
}
func TestMarkdownMessage_ToMessageMap(t *testing.T) {
markdownMsg := NewMarkdownMessage("杭州天气", "#### 杭州天气 @150XXXXXXXX \n > 9度,西北风1级,空气良89,相对温度73%\n > ![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)\n > ###### 10点20分发布 [天气](https://www.dingtalk.com) \n")
markdownMsg.At = NewAt(true)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
res, err := client.SendMessage(markdownMsg)
if err != nil {
t.Error("send message error", err)
}
if res.Success() {
t.Log("send message success")
} else {
t.Errorf("send message error: code: %d msg: %s", res.ErrorCode, res.ErrorMessage)
}
}
func TestNewSingleActionCardMessage(t *testing.T) {
singleActionCardMsg := NewSingleActionCardMessage("乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身",
"![screenshot](https://gw.alicdn.com/tfs/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png) \n ### 乔布斯 20 年前想打造的苹果咖啡厅 \n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划",
"阅读全文",
"https://www.dingtalk.com/",
)
singleActionCardMsg.ToMessageMap()
}
func TestSingleActionCardMessage_ToMessageMap(t *testing.T) {
singleActionCardMsg := NewSingleActionCardMessage("乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身",
"![screenshot](https://gw.alicdn.com/tfs/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png) \n ### 乔布斯 20 年前想打造的苹果咖啡厅 \n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划",
"阅读全文",
"https://www.dingtalk.com/",
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
res, err := client.SendMessage(singleActionCardMsg)
if err != nil {
t.Error("send message error", err)
}
if res.Success() {
t.Log("send message success")
} else {
t.Errorf("send message error: code: %d msg: %s", res.ErrorCode, res.ErrorMessage)
}
}
func TestNewActionCardMessage(t *testing.T) {
actionCardMsg := NewActionCardMessage(
"我 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身",
"![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \n\n #### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划",
NewActionCardButton(
"内容不错",
"https://www.dingtalk.com/",
),
NewActionCardButton(
"不感兴趣",
"https://www.dingtalk.com/",
),
)
actionCardMsg.ToMessageMap()
}
func TestActionCardMessage_ToMessageMap(t *testing.T) {
actionCardMsg := NewActionCardMessage(
"我 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身",
"![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \n\n #### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划",
NewActionCardButton(
"内容不错",
"https://www.dingtalk.com/",
),
)
actionCardMsg.AddButtons(
NewActionCardButton(
"不感兴趣",
"https://www.dingtalk.com/",
),
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
res, err := client.SendMessage(actionCardMsg)
if err != nil {
t.Error("send message error", err)
}
if res.Success() {
t.Log("send message success")
} else {
t.Errorf("send message error: code: %d msg: %s", res.ErrorCode, res.ErrorMessage)
}
}
func TestNewFeedCardMessage(t *testing.T) {
feedCardMsg := NewFeedCardMessage(
NewLink(
"时代的火车向前开1",
"https://www.dingtalk.com/",
"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png",
),
)
feedCardMsg.AddLinks(
NewLink(
"时代的火车向前开2",
"https://www.dingtalk.com/",
"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png",
),
).ToMessageMap()
}
func TestFeedCardMessage_ToMessageMap(t *testing.T) {
feedCardMsg := NewFeedCardMessage(
NewLink(
"时代的火车向前开1",
"https://www.dingtalk.com/",
"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png",
),
)
feedCardMsg.AddLinks(
NewLink(
"时代的火车向前开2",
"https://www.dingtalk.com/",
"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png",
),
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
res, err := client.SendMessage(feedCardMsg)
if err != nil {
t.Error("send message error", err)
}
if res.Success() {
t.Log("send message success")
} else {
t.Errorf("send message error: code: %d msg: %s", res.ErrorCode, res.ErrorMessage)
}
}