all repos — telegram-bot-api @ 0a1b57cdf9f0e93598ff7ad68baec5c403a3c3de

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", "Markdown")
 10
 11	if result.Type != "article" ||
 12		result.ID != "id" ||
 13		result.Title != "title" ||
 14		result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "message" ||
 15		result.InputMessageContent.(tgbotapi.InputTextMessageContent).ParseMode != "Markdown" {
 16		t.Fail()
 17	}
 18}
 19
 20func TestNewInlineQueryResultGIF(t *testing.T) {
 21	result := tgbotapi.NewInlineQueryResultGIF("id", "google.com")
 22
 23	if result.Type != "gif" ||
 24		result.ID != "id" ||
 25		result.URL != "google.com" {
 26		t.Fail()
 27	}
 28}
 29
 30func TestNewInlineQueryResultMPEG4GIF(t *testing.T) {
 31	result := tgbotapi.NewInlineQueryResultMPEG4GIF("id", "google.com")
 32
 33	if result.Type != "mpeg4_gif" ||
 34		result.ID != "id" ||
 35		result.URL != "google.com" {
 36		t.Fail()
 37	}
 38}
 39
 40func TestNewInlineQueryResultPhoto(t *testing.T) {
 41	result := tgbotapi.NewInlineQueryResultPhoto("id", "google.com")
 42
 43	if result.Type != "photo" ||
 44		result.ID != "id" ||
 45		result.URL != "google.com" {
 46		t.Fail()
 47	}
 48}
 49
 50func TestNewInlineQueryResultVideo(t *testing.T) {
 51	result := tgbotapi.NewInlineQueryResultVideo("id", "google.com")
 52
 53	if result.Type != "video" ||
 54		result.ID != "id" ||
 55		result.URL != "google.com" {
 56		t.Fail()
 57	}
 58}
 59
 60func TestNewInlineQueryResultAudio(t *testing.T) {
 61	result := tgbotapi.NewInlineQueryResultAudio("id", "google.com", "title")
 62
 63	if result.Type != "audio" ||
 64		result.ID != "id" ||
 65		result.URL != "google.com" ||
 66		result.Title != "title" {
 67		t.Fail()
 68	}
 69}
 70
 71func TestNewInlineQueryResultVoice(t *testing.T) {
 72	result := tgbotapi.NewInlineQueryResultVoice("id", "google.com", "title")
 73
 74	if result.Type != "voice" ||
 75		result.ID != "id" ||
 76		result.URL != "google.com" ||
 77		result.Title != "title" {
 78		t.Fail()
 79	}
 80}
 81
 82func TestNewInlineQueryResultDocument(t *testing.T) {
 83	result := tgbotapi.NewInlineQueryResultDocument("id", "google.com", "title", "mime/type")
 84
 85	if result.Type != "document" ||
 86		result.ID != "id" ||
 87		result.URL != "google.com" ||
 88		result.Title != "title" ||
 89		result.MimeType != "mime/type" {
 90		t.Fail()
 91	}
 92}
 93
 94func TestNewInlineQueryResultLocation(t *testing.T) {
 95	result := tgbotapi.NewInlineQueryResultLocation("id", "name", 40, 50)
 96
 97	if result.Type != "location" ||
 98		result.ID != "id" ||
 99		result.Title != "name" ||
100		result.Latitude != 40 ||
101		result.Longitude != 50 {
102		t.Fail()
103	}
104}
105
106func TestNewEditMessageText(t *testing.T) {
107	edit := tgbotapi.NewEditMessageText(ChatID, ReplyToMessageID, "new text")
108
109	if edit.Text != "new text" ||
110		edit.BaseEdit.ChatID != ChatID ||
111		edit.BaseEdit.MessageID != ReplyToMessageID {
112		t.Fail()
113	}
114}
115
116func TestNewEditMessageCaption(t *testing.T) {
117	edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption")
118
119	if edit.Caption != "new caption" ||
120		edit.BaseEdit.ChatID != ChatID ||
121		edit.BaseEdit.MessageID != ReplyToMessageID {
122		t.Fail()
123	}
124}
125
126func TestNewEditMessageReplyMarkup(t *testing.T) {
127	markup := tgbotapi.InlineKeyboardMarkup{
128		InlineKeyboard: [][]tgbotapi.InlineKeyboardButton{
129			[]tgbotapi.InlineKeyboardButton{
130				tgbotapi.InlineKeyboardButton{Text: "test"},
131			},
132		},
133	}
134
135	edit := tgbotapi.NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup)
136
137	if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" ||
138		edit.BaseEdit.ChatID != ChatID ||
139		edit.BaseEdit.MessageID != ReplyToMessageID {
140		t.Fail()
141	}
142
143}