-
Notifications
You must be signed in to change notification settings - Fork 1
/
card_test.go
45 lines (40 loc) · 1.11 KB
/
card_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
package larkhertz
import (
"context"
"testing"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/go-lark/lark"
"github.com/stretchr/testify/assert"
)
func TestCardCallback(t *testing.T) {
var (
r = server.Default()
middleware = NewLarkMiddleware()
ok bool
event *lark.EventCardCallback
)
r.Use(middleware.LarkCardHandler())
card := map[string]interface{}{
"app_id": "fake_app_id",
"open_id": "fake_open_id",
"user_id": "f123f456",
"open_message_id": "om_8169c75fbae56c6bebb7e914b92253b4",
"open_chat_id": "fake_oc_id",
"tenant_key": "1068767a888dd740",
"token": "c-2fa8cd831bc83e6350b5be32eb24d2863be4bc5b",
"action": map[string]interface{}{
"tag": "button",
"value": map[string]interface{}{"action": "1"},
},
}
r.POST("/", func(c context.Context, ctx *app.RequestContext) {
event, ok = middleware.GetCardCallback(ctx)
t.Log(event, ok)
})
performRequest(r, "POST", "/", card)
assert.True(t, ok)
if assert.NotNil(t, event) {
assert.Equal(t, "button", event.Action.Tag)
}
}