types_test.go (view raw)
1package tgbotapi_test
2
3import (
4 "github.com/Syfaro/telegram-bot-api"
5 "testing"
6 "time"
7)
8
9func TestUserStringWith(t *testing.T) {
10 user := tgbotapi.User{0, "Test", "Test", ""}
11
12 if user.String() != "Test Test" {
13 t.Fail()
14 }
15}
16
17func TestUserStringWithUserName(t *testing.T) {
18 user := tgbotapi.User{0, "Test", "Test", "@test"}
19
20 if user.String() != "@test" {
21 t.Fail()
22 }
23}
24
25func TestMessageTime(t *testing.T) {
26 message := tgbotapi.Message{Date: 0}
27
28 date := time.Unix(0, 0)
29 if message.Time() != date {
30 t.Fail()
31 }
32}
33
34func TestMessageIsCommandWithCommand(t *testing.T) {
35 message := tgbotapi.Message{Text: "/command"}
36
37 if message.IsCommand() != true {
38 t.Fail()
39 }
40}
41
42func TestIsCommandWithText(t *testing.T) {
43 message := tgbotapi.Message{Text: "some text"}
44
45 if message.IsCommand() != false {
46 t.Fail()
47 }
48}
49
50func TestIsCommandWithEmptyText(t *testing.T) {
51 message := tgbotapi.Message{Text: ""}
52
53 if message.IsCommand() != false {
54 t.Fail()
55 }
56}
57
58func TestCommandWithCommand(t *testing.T) {
59 message := tgbotapi.Message{Text: "/command"}
60
61 if message.Command() != "/command" {
62 t.Fail()
63 }
64}
65
66func TestCommandWithEmptyText(t *testing.T) {
67 message := tgbotapi.Message{Text: ""}
68
69 if message.Command() != "" {
70 t.Fail()
71 }
72}
73
74func TestCommandWithNonCommand(t *testing.T) {
75 message := tgbotapi.Message{Text: "test text"}
76
77 if message.Command() != "" {
78 t.Fail()
79 }
80}
81
82func TestMessageCommandArgumentsWithArguments(t *testing.T) {
83 message := tgbotapi.Message{Text: "/command with arguments"}
84 if message.CommandArguments() != "with arguments" {
85 t.Fail()
86 }
87}
88
89func TestMessageCommandArgumentsWithoutArguments(t *testing.T) {
90 message := tgbotapi.Message{Text: "/command"}
91 if message.CommandArguments() != "" {
92 t.Fail()
93 }
94}
95
96func TestMessageCommandArgumentsForNonCommand(t *testing.T) {
97 message := tgbotapi.Message{Text: "test text"}
98 if message.CommandArguments() != "" {
99 t.Fail()
100 }
101}
102
103func TestChatIsPrivate(t *testing.T) {
104 chat := tgbotapi.Chat{ID: 10, Type: "private"}
105
106 if chat.IsPrivate() != true {
107 t.Fail()
108 }
109}
110
111func TestChatIsGroup(t *testing.T) {
112 chat := tgbotapi.Chat{ID: 10, Type: "group"}
113
114 if chat.IsGroup() != true {
115 t.Fail()
116 }
117}
118
119func TestChatIsChannel(t *testing.T) {
120 chat := tgbotapi.Chat{ID: 10, Type: "channel"}
121
122 if chat.IsChannel() != true {
123 t.Fail()
124 }
125}
126
127func TestChatIsSuperGroup(t *testing.T) {
128 chat := tgbotapi.Chat{ID: 10, Type: "supergroup"}
129
130 if !chat.IsSuperGroup() {
131 t.Fail()
132 }
133}
134
135func TestFileLink(t *testing.T) {
136 file := tgbotapi.File{FilePath: "test/test.txt"}
137
138 if file.Link("token") != "https://api.telegram.org/file/bottoken/test/test.txt" {
139 t.Fail()
140 }
141}