all repos — telegram-bot-api @ 4d758f17d47eba8951d7810190e907db56e51801

Golang bindings for the Telegram Bot API

helpers_test.go (view raw)

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