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