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, 86400)
130
131 if result.Type != "location" ||
132 result.ID != "id" ||
133 result.Title != "name" ||
134 result.Latitude != 40 ||
135 result.Longitude != 50 ||
136 result.LivePeriod != 86400 {
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}