all repos — telegram-bot-api @ bf6e165e92e6da5dd62b859f8397f7c8864e4b04

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