-
Notifications
You must be signed in to change notification settings - Fork 11
/
call_test.go
61 lines (41 loc) · 1.25 KB
/
call_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
package tg
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBindClient(t *testing.T) {
t.Run("Call", func(t *testing.T) {
call := NewGetMeCall()
assert.Nil(t, call.client)
BindClient(call, &Client{})
assert.NotNil(t, call.client)
})
t.Run("CallNoResult", func(t *testing.T) {
call := NewSetChatTitleCall(ChatID(1), "Hello")
assert.Nil(t, call.client)
BindClient(call, &Client{})
assert.NotNil(t, call.client)
})
}
func TestCall_MarshalJSON(t *testing.T) {
call := NewSendMessageCall(ChatID(1), "Hello")
v, err := call.MarshalJSON()
assert.NoError(t, err)
assert.JSONEq(t, `{"chat_id":"1","text":"Hello","method":"sendMessage"}`, string(v))
}
func TestCallNoResult_MarshalJSON(t *testing.T) {
call := NewSetChatTitleCall(ChatID(1), "Hello")
v, err := call.MarshalJSON()
assert.NoError(t, err)
assert.JSONEq(t, `{"chat_id":"1","title":"Hello","method":"setChatTitle"}`, string(v))
}
func TestCall_Request(t *testing.T) {
call := NewGetMeCall()
assert.NotNil(t, call.Request())
assert.Equal(t, "getMe", call.Request().Method)
}
func TestCallNoResult_Request(t *testing.T) {
call := NewSetChatTitleCall(ChatID(1), "Hello")
assert.NotNil(t, call.Request())
assert.Equal(t, "setChatTitle", call.Request().Method)
}