-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_v2_test.go
65 lines (60 loc) · 1.7 KB
/
event_v2_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
package larkgin
import (
"testing"
"github.com/gin-gonic/gin"
"github.com/go-lark/lark"
"github.com/stretchr/testify/assert"
)
func TestEventV2(t *testing.T) {
var (
r = gin.Default()
middleware = NewLarkMiddleware()
ok bool
event *lark.EventV2
)
r.Use(middleware.LarkEventHandler())
r.POST("/", func(c *gin.Context) {
event, ok = middleware.GetEvent(c)
})
message := map[string]interface{}{
"schema": "2.0",
"header": map[string]interface{}{
"event_id": "8295112f4e107daafa9aa169e746c627",
"token": "Si0qr61OaX02zPtzudllLgSDOXaKyNy0",
"create_time": "1641385820880",
"event_type": "im.message.receive_v1",
"tenant_key": "7",
"app_id": "6",
},
"event": map[string]interface{}{
"message": map[string]interface{}{
"chat_id": "oc_ae7f3952a9b28588aeac46c9853d25d3",
"chat_type": "p2p",
"content": "{\"text\":\"333\"}",
"create_time": "1641385820771",
"message_id": "om_6ff2cff41a3e9248bbb19bf0e4762e6e",
"message_type": "text",
},
"sender": map[string]interface{}{
"sender_id": map[string]interface{}{
"open_id": "ou_4f75b532aff410181e93552ad0532072",
"union_id": "on_2312aab89ab7c87beb9a443b2f3b1342",
"user_id": "4gbb63af",
},
"sender_type": "user",
"tenant_key": "736588c9260f175d",
},
},
}
performRequest(r, "POST", "/", message)
assert.True(t, ok)
if assert.NotNil(t, event) {
assert.Equal(t, "im.message.receive_v1", event.Header.EventType)
assert.Equal(t, "2.0", event.Schema)
assert.Equal(t, "6", event.Header.AppID)
msg, err := event.GetMessageReceived()
if assert.NoError(t, err) {
assert.Equal(t, "{\"text\":\"333\"}", msg.Message.Content)
}
}
}