forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
member_test.go
64 lines (57 loc) · 1.44 KB
/
member_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
//go:build !integration
// +build !integration
package disgord
import (
"testing"
"time"
"github.com/andersfylling/disgord/json"
)
func TestUpdateMemberParams(t *testing.T) {
ts := time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC) // 1st jan 2022
trueBool := true
testCases := map[string]struct {
encoded string
body *UpdateMember
}{
"encoded future timeout time": {
encoded: `{"mute":true,"communication_disabled_until":"2022-01-01T00:00:00.000000+00:00"}`,
body: &UpdateMember{
Mute: &trueBool,
CommunicationDisabledUntil: &Time{Time: ts},
},
},
"no timeout struct provided": {
encoded: `{"mute":true,"deaf":true}`,
body: &UpdateMember{
Mute: &trueBool,
Deaf: &trueBool,
},
},
"nil timeout value": {
encoded: `{"mute":true}`,
body: &UpdateMember{
Mute: &trueBool,
CommunicationDisabledUntil: nil,
},
},
"remove timeout": {
encoded: `{"mute":true,"communication_disabled_until":""}`,
body: &UpdateMember{
Mute: &trueBool,
CommunicationDisabledUntil: &Time{},
},
},
}
for name, testCase := range testCases {
testCase := testCase // move to scope
t.Run(name, func(t *testing.T) {
bytes, err := json.Marshal(testCase.body)
if err != nil {
t.Fatal(err)
}
if resp := string(bytes); resp != testCase.encoded {
t.Errorf("wanted %s - got %s", testCase.encoded, resp)
}
})
}
}