-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsample-component_test.go
108 lines (101 loc) · 2.81 KB
/
sample-component_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
package corde_test
import (
"context"
"net/http/httptest"
"testing"
"github.com/Karitham/corde"
"github.com/Karitham/corde/owmock"
"github.com/matryer/is"
)
func TestComponentInteraction(t *testing.T) {
assert := is.New(t)
pub, _ := owmock.GenerateKeys()
mux := corde.NewMux(pub, 0, "")
mux.OnNotFound = func(ctx context.Context, _ corde.ResponseWriter, ir *corde.Interaction[corde.JsonRaw]) {
t.Log(ir)
}
mux.ButtonComponent("click_one", func(ctx context.Context, w corde.ResponseWriter, _ *corde.Interaction[corde.ButtonInteractionData]) {
w.Respond(&corde.InteractionRespData{
Content: "Hello World!",
})
})
expect := &owmock.InteractionResponse{
Type: 4,
Data: corde.InteractionRespData{
Content: "Hello World!",
},
}
s := httptest.NewServer(mux)
err := owmock.NewWithClient(s.URL, s.Client()).PostExpect(t, SampleComponent, expect)
assert.NoErr(err)
}
const SampleComponent = `{
"version": 1,
"type": 3,
"token": "unique_interaction_token",
"message": {
"type": 0,
"tts": false,
"timestamp": "2021-05-19T02:12:51.710000+00:00",
"pinned": false,
"mentions": [],
"mention_roles": [],
"mention_everyone": false,
"id": "844397162624450620",
"flags": 0,
"embeds": [],
"edited_timestamp": null,
"content": "This is a message with ",
"components": [
{
"type": 1,
"components": [
{
"type": 2,
"label": "Click me!",
"style": 1,
"custom_id": "click_one"
}
]
}
],
"channel_id": "345626669114982402",
"author": {
"username": "Mason",
"public_flags": 131141,
"id": "53908232506183680",
"discriminator": "1337",
"avatar": "a_d5efa99b3eeaa7dd43acca82f5692432"
},
"attachments": []
},
"member": {
"user": {
"username": "Mason",
"public_flags": 131141,
"id": "53908232506183680",
"discriminator": "1337",
"avatar": "a_d5efa99b3eeaa7dd43acca82f5692432"
},
"roles": [
"290926798626357999"
],
"premium_since": null,
"permissions": "17179869183",
"pending": false,
"nick": null,
"mute": false,
"joined_at": "2017-03-13T19:19:14.040000+00:00",
"is_pending": false,
"deaf": false,
"avatar": null
},
"id": "846462639134605312",
"guild_id": "290926798626357999",
"data": {
"custom_id": "click_one",
"component_type": 2
},
"channel_id": "345626669114982999",
"application_id": "290926444748734465"
}`