types_test.go (view raw)
1package tgbotapi_test
2
3import (
4 "github.com/go-telegram-bot-api/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 TestCommandWithBotName(t *testing.T) {
83 message := tgbotapi.Message{Text: "/command@testbot"}
84
85 if message.Command() != "command" {
86 t.Fail()
87 }
88}
89
90func TestMessageCommandArgumentsWithArguments(t *testing.T) {
91 message := tgbotapi.Message{Text: "/command with arguments"}
92 if message.CommandArguments() != "with arguments" {
93 t.Fail()
94 }
95}
96
97func TestMessageCommandArgumentsWithoutArguments(t *testing.T) {
98 message := tgbotapi.Message{Text: "/command"}
99 if message.CommandArguments() != "" {
100 t.Fail()
101 }
102}
103
104func TestMessageCommandArgumentsForNonCommand(t *testing.T) {
105 message := tgbotapi.Message{Text: "test text"}
106 if message.CommandArguments() != "" {
107 t.Fail()
108 }
109}
110
111func TestMessageEntityParseURLGood(t *testing.T) {
112 entity := tgbotapi.MessageEntity{URL: "https://www.google.com"}
113
114 if _, err := entity.ParseURL(); err != nil {
115 t.Fail()
116 }
117}
118
119func TestMessageEntityParseURLBad(t *testing.T) {
120 entity := tgbotapi.MessageEntity{URL: ""}
121
122 if _, err := entity.ParseURL(); err == nil {
123 t.Fail()
124 }
125}
126
127func TestChatIsPrivate(t *testing.T) {
128 chat := tgbotapi.Chat{ID: 10, Type: "private"}
129
130 if chat.IsPrivate() != true {
131 t.Fail()
132 }
133}
134
135func TestChatIsGroup(t *testing.T) {
136 chat := tgbotapi.Chat{ID: 10, Type: "group"}
137
138 if chat.IsGroup() != true {
139 t.Fail()
140 }
141}
142
143func TestChatIsChannel(t *testing.T) {
144 chat := tgbotapi.Chat{ID: 10, Type: "channel"}
145
146 if chat.IsChannel() != true {
147 t.Fail()
148 }
149}
150
151func TestChatIsSuperGroup(t *testing.T) {
152 chat := tgbotapi.Chat{ID: 10, Type: "supergroup"}
153
154 if !chat.IsSuperGroup() {
155 t.Fail()
156 }
157}
158
159func TestFileLink(t *testing.T) {
160 file := tgbotapi.File{FilePath: "test/test.txt"}
161
162 if file.Link("token") != "https://api.telegram.org/file/bottoken/test/test.txt" {
163 t.Fail()
164 }
165}