-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_later_processor_test.go
123 lines (112 loc) · 3.1 KB
/
update_later_processor_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
package router
import (
"context"
"github.com/Postcord/objects"
"github.com/Postcord/rest"
"github.com/stretchr/testify/assert"
"testing"
)
type mockRestEditInteractionParams struct {
applicationID objects.Snowflake
token string
params *rest.EditWebhookMessageParams
}
type mockRestEditInteractionResponse struct {
t *testing.T
params *mockRestEditInteractionParams
}
func newMockRestEditInteractionResponse(t *testing.T) *mockRestEditInteractionResponse {
return &mockRestEditInteractionResponse{t: t}
}
func (m *mockRestEditInteractionResponse) EditOriginalInteractionResponse(reqCtx context.Context, applicationID objects.SnowflakeObject, token string, params *rest.EditWebhookMessageParams) (*objects.Message, error) {
m.t.Helper()
if m.params != nil {
m.t.Fatal("edit interaction already called")
return nil, nil
}
m.params = &mockRestEditInteractionParams{
applicationID: applicationID.GetID(),
token: token,
params: params,
}
return nil, nil
}
func Test_processUpdateLaterResponse(t *testing.T) {
tests := []struct {
name string
applicationID objects.Snowflake
token string
response *objects.InteractionResponse
restParams *mockRestEditInteractionParams
}{
{
name: "deferred message update",
applicationID: 1,
token: "a",
response: &objects.InteractionResponse{Type: objects.ResponseDeferredMessageUpdate},
},
{
name: "deferred channel message with source",
applicationID: 1,
token: "a",
response: &objects.InteractionResponse{Type: objects.ResponseDeferredChannelMessageWithSource},
},
{
name: "update message",
applicationID: 1,
token: "a",
response: &objects.InteractionResponse{
Type: objects.ResponseUpdateMessage,
Data: &objects.InteractionApplicationCommandCallbackData{
Content: "Hello World",
Embeds: []*objects.Embed{
{
Title: "a embed",
},
},
AllowedMentions: &objects.AllowedMentions{
Parse: []string{"1"},
Roles: []objects.Snowflake{2},
Users: []objects.Snowflake{3},
RepliedUser: true,
},
Components: []*objects.Component{
{
Label: "Testing testing 123",
},
},
},
},
restParams: &mockRestEditInteractionParams{
applicationID: 1,
token: "a",
params: &rest.EditWebhookMessageParams{
Content: "Hello World",
Embeds: []*objects.Embed{
{
Title: "a embed",
},
},
AllowedMentions: &objects.AllowedMentions{
Parse: []string{"1"},
Roles: []objects.Snowflake{2},
Users: []objects.Snowflake{3},
RepliedUser: true,
},
Components: []*objects.Component{
{
Label: "Testing testing 123",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
restClient := newMockRestEditInteractionResponse(t)
processUpdateLaterResponse(context.Background(), restClient, tt.applicationID, tt.token, tt.response)
assert.Equal(t, tt.restParams, restClient.params)
})
}
}