-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathmedia_test.go
More file actions
76 lines (70 loc) · 1.56 KB
/
media_test.go
File metadata and controls
76 lines (70 loc) · 1.56 KB
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
package telebot
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
)
func TestAlbumSetCaption(t *testing.T) {
tests := []struct {
name string
media Inputtable
}{
{
name: "photo",
media: &Photo{Caption: "wrong_caption"},
},
{
name: "animation",
media: &Animation{Caption: "wrong_caption"},
},
{
name: "video",
media: &Video{Caption: "wrong_caption"},
},
{
name: "audio",
media: &Audio{Caption: "wrong_caption"},
},
{
name: "document",
media: &Document{Caption: "wrong_caption"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var a Album
a = append(a, tt.media)
a = append(a, &Photo{Caption: "random_caption"})
a.SetCaption("correct_caption")
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
assert.Equal(t, "random_caption", a[1].InputMedia().Caption)
})
}
}
func TestPaidMediaPurchased(t *testing.T) {
jsonData := `{
"from": {
"id": 123,
"is_bot": false,
"first_name": "Test"
},
"paid_media_payload": "test_payload_123"
}`
var pmp PaidMediaPurchased
err := json.Unmarshal([]byte(jsonData), &pmp)
assert.NoError(t, err)
assert.NotNil(t, pmp.From)
assert.Equal(t, int64(123), pmp.From.ID)
assert.Equal(t, "test_payload_123", pmp.Payload)
}
func TestPaidMediaPayload(t *testing.T) {
jsonData := `{
"type": "photo",
"payload": "custom_payload"
}`
var pm PaidMedia
err := json.Unmarshal([]byte(jsonData), &pm)
assert.NoError(t, err)
assert.Equal(t, "photo", pm.Type)
assert.Equal(t, "custom_payload", pm.Payload)
}