helpers_test.go (view raw)
1package tgbotapi
2
3import (
4 "testing"
5)
6
7func TestNewInlineQueryResultArticle(t *testing.T) {
8 result := NewInlineQueryResultArticle("id", "title", "message")
9
10 if result.Type != "article" ||
11 result.ID != "id" ||
12 result.Title != "title" ||
13 result.InputMessageContent.(InputTextMessageContent).Text != "message" {
14 t.Fail()
15 }
16}
17
18func TestNewInlineQueryResultArticleMarkdown(t *testing.T) {
19 result := NewInlineQueryResultArticleMarkdown("id", "title", "*message*")
20
21 if result.Type != "article" ||
22 result.ID != "id" ||
23 result.Title != "title" ||
24 result.InputMessageContent.(InputTextMessageContent).Text != "*message*" ||
25 result.InputMessageContent.(InputTextMessageContent).ParseMode != "Markdown" {
26 t.Fail()
27 }
28}
29
30func TestNewInlineQueryResultArticleHTML(t *testing.T) {
31 result := NewInlineQueryResultArticleHTML("id", "title", "<b>message</b>")
32
33 if result.Type != "article" ||
34 result.ID != "id" ||
35 result.Title != "title" ||
36 result.InputMessageContent.(InputTextMessageContent).Text != "<b>message</b>" ||
37 result.InputMessageContent.(InputTextMessageContent).ParseMode != "HTML" {
38 t.Fail()
39 }
40}
41
42func TestNewInlineQueryResultGIF(t *testing.T) {
43 result := NewInlineQueryResultGIF("id", "google.com")
44
45 if result.Type != "gif" ||
46 result.ID != "id" ||
47 result.URL != "google.com" {
48 t.Fail()
49 }
50}
51
52func TestNewInlineQueryResultMPEG4GIF(t *testing.T) {
53 result := NewInlineQueryResultMPEG4GIF("id", "google.com")
54
55 if result.Type != "mpeg4_gif" ||
56 result.ID != "id" ||
57 result.URL != "google.com" {
58 t.Fail()
59 }
60}
61
62func TestNewInlineQueryResultPhoto(t *testing.T) {
63 result := NewInlineQueryResultPhoto("id", "google.com")
64
65 if result.Type != "photo" ||
66 result.ID != "id" ||
67 result.URL != "google.com" {
68 t.Fail()
69 }
70}
71
72func TestNewInlineQueryResultPhotoWithThumb(t *testing.T) {
73 result := NewInlineQueryResultPhotoWithThumb("id", "google.com", "thumb.com")
74
75 if result.Type != "photo" ||
76 result.ID != "id" ||
77 result.URL != "google.com" ||
78 result.ThumbURL != "thumb.com" {
79 t.Fail()
80 }
81}
82
83func TestNewInlineQueryResultVideo(t *testing.T) {
84 result := NewInlineQueryResultVideo("id", "google.com")
85
86 if result.Type != "video" ||
87 result.ID != "id" ||
88 result.URL != "google.com" {
89 t.Fail()
90 }
91}
92
93func TestNewInlineQueryResultAudio(t *testing.T) {
94 result := NewInlineQueryResultAudio("id", "google.com", "title")
95
96 if result.Type != "audio" ||
97 result.ID != "id" ||
98 result.URL != "google.com" ||
99 result.Title != "title" {
100 t.Fail()
101 }
102}
103
104func TestNewInlineQueryResultVoice(t *testing.T) {
105 result := NewInlineQueryResultVoice("id", "google.com", "title")
106
107 if result.Type != "voice" ||
108 result.ID != "id" ||
109 result.URL != "google.com" ||
110 result.Title != "title" {
111 t.Fail()
112 }
113}
114
115func TestNewInlineQueryResultDocument(t *testing.T) {
116 result := NewInlineQueryResultDocument("id", "google.com", "title", "mime/type")
117
118 if result.Type != "document" ||
119 result.ID != "id" ||
120 result.URL != "google.com" ||
121 result.Title != "title" ||
122 result.MimeType != "mime/type" {
123 t.Fail()
124 }
125}
126
127func TestNewInlineQueryResultLocation(t *testing.T) {
128 result := NewInlineQueryResultLocation("id", "name", 40, 50)
129
130 if result.Type != "location" ||
131 result.ID != "id" ||
132 result.Title != "name" ||
133 result.Latitude != 40 ||
134 result.Longitude != 50 {
135 t.Fail()
136 }
137}
138
139func TestNewInlineKeyboardButtonLoginURL(t *testing.T) {
140 result := NewInlineKeyboardButtonLoginURL("text", LoginURL{
141 URL: "url",
142 ForwardText: "ForwardText",
143 BotUsername: "username",
144 RequestWriteAccess: false,
145 })
146
147 if result.Text != "text" ||
148 result.LoginURL.URL != "url" ||
149 result.LoginURL.ForwardText != "ForwardText" ||
150 result.LoginURL.BotUsername != "username" ||
151 result.LoginURL.RequestWriteAccess != false {
152 t.Fail()
153 }
154}
155
156func TestNewEditMessageText(t *testing.T) {
157 edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text")
158
159 if edit.Text != "new text" ||
160 edit.BaseEdit.ChatID != ChatID ||
161 edit.BaseEdit.MessageID != ReplyToMessageID {
162 t.Fail()
163 }
164}
165
166func TestNewEditMessageCaption(t *testing.T) {
167 edit := NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption")
168
169 if edit.Caption != "new caption" ||
170 edit.BaseEdit.ChatID != ChatID ||
171 edit.BaseEdit.MessageID != ReplyToMessageID {
172 t.Fail()
173 }
174}
175
176func TestNewEditMessageReplyMarkup(t *testing.T) {
177 markup := InlineKeyboardMarkup{
178 InlineKeyboard: [][]InlineKeyboardButton{
179 []InlineKeyboardButton{
180 InlineKeyboardButton{Text: "test"},
181 },
182 },
183 }
184
185 edit := NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup)
186
187 if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" ||
188 edit.BaseEdit.ChatID != ChatID ||
189 edit.BaseEdit.MessageID != ReplyToMessageID {
190 t.Fail()
191 }
192
193}