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