all repos — telegram-bot-api @ 1daed40422d154dcd781d9fa6b5ca1add15635bf

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 TestNewInlineQueryResultVideo(t *testing.T) {
 74	result := tgbotapi.NewInlineQueryResultVideo("id", "google.com")
 75
 76	if result.Type != "video" ||
 77		result.ID != "id" ||
 78		result.URL != "google.com" {
 79		t.Fail()
 80	}
 81}
 82
 83func TestNewInlineQueryResultAudio(t *testing.T) {
 84	result := tgbotapi.NewInlineQueryResultAudio("id", "google.com", "title")
 85
 86	if result.Type != "audio" ||
 87		result.ID != "id" ||
 88		result.URL != "google.com" ||
 89		result.Title != "title" {
 90		t.Fail()
 91	}
 92}
 93
 94func TestNewInlineQueryResultVoice(t *testing.T) {
 95	result := tgbotapi.NewInlineQueryResultVoice("id", "google.com", "title")
 96
 97	if result.Type != "voice" ||
 98		result.ID != "id" ||
 99		result.URL != "google.com" ||
100		result.Title != "title" {
101		t.Fail()
102	}
103}
104
105func TestNewInlineQueryResultDocument(t *testing.T) {
106	result := tgbotapi.NewInlineQueryResultDocument("id", "google.com", "title", "mime/type")
107
108	if result.Type != "document" ||
109		result.ID != "id" ||
110		result.URL != "google.com" ||
111		result.Title != "title" ||
112		result.MimeType != "mime/type" {
113		t.Fail()
114	}
115}
116
117func TestNewInlineQueryResultLocation(t *testing.T) {
118	result := tgbotapi.NewInlineQueryResultLocation("id", "name", 40, 50)
119
120	if result.Type != "location" ||
121		result.ID != "id" ||
122		result.Title != "name" ||
123		result.Latitude != 40 ||
124		result.Longitude != 50 {
125		t.Fail()
126	}
127}
128
129func TestNewEditMessageText(t *testing.T) {
130	edit := tgbotapi.NewEditMessageText(ChatID, ReplyToMessageID, "new text")
131
132	if edit.Text != "new text" ||
133		edit.BaseEdit.ChatID != ChatID ||
134		edit.BaseEdit.MessageID != ReplyToMessageID {
135		t.Fail()
136	}
137}
138
139func TestNewEditMessageCaption(t *testing.T) {
140	edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption")
141
142	if edit.Caption != "new caption" ||
143		edit.BaseEdit.ChatID != ChatID ||
144		edit.BaseEdit.MessageID != ReplyToMessageID {
145		t.Fail()
146	}
147}
148
149func TestNewEditMessageReplyMarkup(t *testing.T) {
150	markup := tgbotapi.InlineKeyboardMarkup{
151		InlineKeyboard: [][]tgbotapi.InlineKeyboardButton{
152			[]tgbotapi.InlineKeyboardButton{
153				tgbotapi.InlineKeyboardButton{Text: "test"},
154			},
155		},
156	}
157
158	edit := tgbotapi.NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup)
159
160	if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" ||
161		edit.BaseEdit.ChatID != ChatID ||
162		edit.BaseEdit.MessageID != ReplyToMessageID {
163		t.Fail()
164	}
165
166}