all repos — telegram-bot-api @ 483f21c48bebae648c4464138be96b1344151035

Golang bindings for the Telegram Bot API

helpers_test.go (view raw)

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