-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
api_notification_test.go
102 lines (87 loc) · 3.06 KB
/
api_notification_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
package lark
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// A weird case which sends V2 message body with V1 URL
func TestWebhookV1Error(t *testing.T) {
bot := NewNotificationBot(testWebhookV1)
mbText := NewMsgBuffer(MsgText)
mbText.Text("hello")
resp, err := bot.PostNotificationV2(mbText.Build())
assert.NoError(t, err)
assert.Zero(t, resp.StatusCode)
}
func TestWebhookV2(t *testing.T) {
bot := NewNotificationBot(testWebhookV2)
mbText := NewMsgBuffer(MsgText)
mbText.Text("hello")
resp, err := bot.PostNotificationV2(mbText.Build())
assert.NoError(t, err)
assert.Zero(t, resp.StatusCode)
assert.Equal(t, "success", resp.StatusMessage)
mbPost := NewMsgBuffer(MsgPost)
mbPost.Post(NewPostBuilder().Title("hello").TextTag("world", 1, true).Render())
resp, err = bot.PostNotificationV2(mbPost.Build())
assert.NoError(t, err)
assert.Zero(t, resp.StatusCode)
assert.Equal(t, "success", resp.StatusMessage)
mbImg := NewMsgBuffer(MsgImage)
mbImg.Image("img_a97c1597-9c0a-47c1-9fb4-dd3e5e37ac9g")
resp, err = bot.PostNotificationV2(mbImg.Build())
assert.NoError(t, err)
assert.Zero(t, resp.StatusCode)
assert.Equal(t, "success", resp.StatusMessage)
mbShareGroup := NewMsgBuffer(MsgShareCard)
mbShareGroup.ShareChat(testGroupChatID)
resp, err = bot.PostNotificationV2(mbShareGroup.Build())
assert.NoError(t, err)
assert.Zero(t, resp.StatusCode)
assert.Equal(t, "success", resp.StatusMessage)
}
func TestWebhookV2CardMessage(t *testing.T) {
bot := NewNotificationBot(testWebhookV2)
b := NewCardBuilder()
card := b.Card(
b.Div(
b.Field(b.Text("左侧内容")).Short(),
b.Field(b.Text("右侧内容")).Short(),
b.Field(b.Text("整排内容")),
b.Field(b.Text("整排**Markdown**内容").LarkMd()),
),
b.Div().
Text(b.Text("Text Content")).
Extra(b.Img("img_a7c6aa35-382a-48ad-839d-d0182a69b4dg")),
b.Note().
AddText(b.Text("Note **Text**").LarkMd()).
AddImage(b.Img("img_a7c6aa35-382a-48ad-839d-d0182a69b4dg")),
).
Wathet().
Title("Notification Card")
msgV4 := NewMsgBuffer(MsgInteractive)
omV4 := msgV4.Card(card.String()).Build()
resp, err := bot.PostNotificationV2(omV4)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.StatusCode)
assert.NotEmpty(t, resp.StatusMessage)
}
}
func TestWebhookV2Signed(t *testing.T) {
bot := NewNotificationBot(testWebhookV2Signed)
mbText := NewMsgBuffer(MsgText)
mbText.Text("hello sign").WithSign("FT1dnAgPYYTcpafMTkhPjc", time.Now().Unix())
resp, err := bot.PostNotificationV2(mbText.Build())
assert.NoError(t, err)
assert.Zero(t, resp.StatusCode)
assert.Equal(t, "success", resp.StatusMessage)
}
func TestWebhookV2SignedError(t *testing.T) {
bot := NewNotificationBot("https://open.feishu.cn/open-apis/bot/v2/hook/749be902-6eaa-4cc3-9325-be4126164b02")
mbText := NewMsgBuffer(MsgText)
mbText.Text("hello sign").WithSign("LIpnNexV7rwOyOebKoqSdb", time.Now().Unix())
resp, err := bot.PostNotificationV2(mbText.Build())
assert.NoError(t, err)
assert.Zero(t, resp.StatusCode)
assert.Equal(t, "sign match fail or timestamp is not within one hour from current time", resp.Msg)
}