-
Notifications
You must be signed in to change notification settings - Fork 11
/
reactions_test.go
80 lines (57 loc) · 1.73 KB
/
reactions_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
package tg
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReactionType(t *testing.T) {
t.Run("Emoji", func(t *testing.T) {
var r ReactionType
err := r.UnmarshalJSON([]byte(`{"type": "emoji", "emoji": "😀"}`))
require.NoError(t, err)
assert.Equal(t, "emoji", r.Type())
require.NotNil(t, r.Emoji)
assert.Equal(t, "😀", r.Emoji.Emoji)
})
t.Run("CustomEmoji", func(t *testing.T) {
var r ReactionType
err := r.UnmarshalJSON([]byte(`{"type": "custom_emoji", "custom_emoji_id": "12345"}`))
require.NoError(t, err)
assert.Equal(t, "custom_emoji", r.Type())
require.NotNil(t, r.CustomEmoji)
assert.Equal(t, "12345", r.CustomEmoji.CustomEmojiID)
})
t.Run("Unknown", func(t *testing.T) {
var r ReactionType
err := r.UnmarshalJSON([]byte(`{"type": "unknown"}`))
require.Error(t, err)
})
t.Run("InvalidFieldType", func(t *testing.T) {
var r ReactionType
err := r.UnmarshalJSON([]byte(`{"type": 123}`))
require.Error(t, err)
})
}
func TestReactionType_MarshalJSON(t *testing.T) {
t.Run("Emoji", func(t *testing.T) {
r := NewReactionTypeEmoji("😀")
assert.Equal(t, "emoji", r.Type())
b, err := json.Marshal(r)
require.NoError(t, err)
assert.Equal(t, `{"type":"emoji","emoji":"😀"}`, string(b))
})
t.Run("CustomEmoji", func(t *testing.T) {
r := NewReactionTypeCustomEmoji("12345")
assert.Equal(t, "custom_emoji", r.Type())
b, err := json.Marshal(r)
require.NoError(t, err)
assert.Equal(t, `{"type":"custom_emoji","custom_emoji_id":"12345"}`, string(b))
})
t.Run("Unknown", func(t *testing.T) {
r := ReactionType{}
assert.Equal(t, "unknown", r.Type())
_, err := json.Marshal(r)
require.Error(t, err)
})
}