all repos — telegram-bot-api @ b16df76f2eb1f7a91d953450401afa1ba4a93add

Golang bindings for the Telegram Bot API

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 TestNewEditMessageText(t *testing.T) {
140	edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text")
141
142	if edit.Text != "new text" ||
143		edit.BaseEdit.ChatID != ChatID ||
144		edit.BaseEdit.MessageID != ReplyToMessageID {
145		t.Fail()
146	}
147}
148
149func TestNewEditMessageCaption(t *testing.T) {
150	edit := NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption")
151
152	if edit.Caption != "new caption" ||
153		edit.BaseEdit.ChatID != ChatID ||
154		edit.BaseEdit.MessageID != ReplyToMessageID {
155		t.Fail()
156	}
157}
158
159func TestNewEditMessageReplyMarkup(t *testing.T) {
160	markup := InlineKeyboardMarkup{
161		InlineKeyboard: [][]InlineKeyboardButton{
162			[]InlineKeyboardButton{
163				InlineKeyboardButton{Text: "test"},
164			},
165		},
166	}
167
168	edit := NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup)
169
170	if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" ||
171		edit.BaseEdit.ChatID != ChatID ||
172		edit.BaseEdit.MessageID != ReplyToMessageID {
173		t.Fail()
174	}
175
176}