all repos — telegram-bot-api @ 53d566ba56fb4b9925de3aeb74726e870f8d2e1d

Golang bindings for the Telegram Bot API

helpers_test.go (view raw)

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