Skip to content

Commit e7b9f16

Browse files
author
Syfaro
committed
Add missing helpers, move helper tests to own file.
1 parent ed7fe62 commit e7b9f16

File tree

3 files changed

+179
-89
lines changed

3 files changed

+179
-89
lines changed

bot_test.go

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -419,95 +419,6 @@ func TestSetWebhookWithoutCert(t *testing.T) {
419419
bot.RemoveWebhook()
420420
}
421421

422-
func TestNewInlineQueryResultArticle(t *testing.T) {
423-
result := tgbotapi.NewInlineQueryResultArticle("id", "title", "message")
424-
425-
if result.Type != "article" ||
426-
result.ID != "id" ||
427-
result.Title != "title" ||
428-
result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "message" {
429-
t.Fail()
430-
}
431-
}
432-
433-
func TestNewInlineQueryResultGIF(t *testing.T) {
434-
result := tgbotapi.NewInlineQueryResultGIF("id", "google.com")
435-
436-
if result.Type != "gif" ||
437-
result.ID != "id" ||
438-
result.URL != "google.com" {
439-
t.Fail()
440-
}
441-
}
442-
443-
func TestNewInlineQueryResultMPEG4GIF(t *testing.T) {
444-
result := tgbotapi.NewInlineQueryResultMPEG4GIF("id", "google.com")
445-
446-
if result.Type != "mpeg4_gif" ||
447-
result.ID != "id" ||
448-
result.URL != "google.com" {
449-
t.Fail()
450-
}
451-
}
452-
453-
func TestNewInlineQueryResultPhoto(t *testing.T) {
454-
result := tgbotapi.NewInlineQueryResultPhoto("id", "google.com")
455-
456-
if result.Type != "photo" ||
457-
result.ID != "id" ||
458-
result.URL != "google.com" {
459-
t.Fail()
460-
}
461-
}
462-
463-
func TestNewInlineQueryResultVideo(t *testing.T) {
464-
result := tgbotapi.NewInlineQueryResultVideo("id", "google.com")
465-
466-
if result.Type != "video" ||
467-
result.ID != "id" ||
468-
result.URL != "google.com" {
469-
}
470-
}
471-
472-
func TestNewEditMessageText(t *testing.T) {
473-
edit := tgbotapi.NewEditMessageText(ChatID, ReplyToMessageID, "new text")
474-
475-
if edit.Text != "new text" ||
476-
edit.BaseEdit.ChatID != ChatID ||
477-
edit.BaseEdit.MessageID != ReplyToMessageID {
478-
t.Fail()
479-
}
480-
}
481-
482-
func TestNewEditMessageCaption(t *testing.T) {
483-
edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption")
484-
485-
if edit.Caption != "new caption" ||
486-
edit.BaseEdit.ChatID != ChatID ||
487-
edit.BaseEdit.MessageID != ReplyToMessageID {
488-
t.Fail()
489-
}
490-
}
491-
492-
func TestNewEditMessageReplyMarkup(t *testing.T) {
493-
markup := tgbotapi.InlineKeyboardMarkup{
494-
InlineKeyboard: [][]tgbotapi.InlineKeyboardButton{
495-
[]tgbotapi.InlineKeyboardButton{
496-
tgbotapi.InlineKeyboardButton{Text: "test"},
497-
},
498-
},
499-
}
500-
501-
edit := tgbotapi.NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup)
502-
503-
if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" ||
504-
edit.BaseEdit.ChatID != ChatID ||
505-
edit.BaseEdit.MessageID != ReplyToMessageID {
506-
t.Fail()
507-
}
508-
509-
}
510-
511422
func TestUpdatesChan(t *testing.T) {
512423
bot, _ := getBot(t)
513424

helpers.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,48 @@ func NewInlineQueryResultVideo(id, url string) InlineQueryResultVideo {
352352
}
353353
}
354354

355+
// NewInlineQueryResultAudio creates a new inline query audio.
356+
func NewInlineQueryResultAudio(id, url, title string) InlineQueryResultAudio {
357+
return InlineQueryResultAudio{
358+
Type: "audio",
359+
ID: id,
360+
URL: url,
361+
Title: title,
362+
}
363+
}
364+
365+
// NewInlineQueryResultVoice creates a new inline query voice.
366+
func NewInlineQueryResultVoice(id, url, title string) InlineQueryResultVoice {
367+
return InlineQueryResultVoice{
368+
Type: "voice",
369+
ID: id,
370+
URL: url,
371+
Title: title,
372+
}
373+
}
374+
375+
// NewInlineQueryResultDocument creates a new inline query document.
376+
func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryResultDocument {
377+
return InlineQueryResultDocument{
378+
Type: "document",
379+
ID: id,
380+
URL: url,
381+
Title: title,
382+
MimeType: mimeType,
383+
}
384+
}
385+
386+
// NewInlineQueryResultLocation creates a new inline query location.
387+
func NewInlineQueryResultLocation(id, title string, latitude, longitude float64) InlineQueryResultLocation {
388+
return InlineQueryResultLocation{
389+
Type: "location",
390+
ID: id,
391+
Title: title,
392+
Latitude: latitude,
393+
Longitude: longitude,
394+
}
395+
}
396+
355397
// NewEditMessageText allows you to edit the text of a message.
356398
func NewEditMessageText(chatID int64, messageID int, text string) EditMessageTextConfig {
357399
return EditMessageTextConfig{

helpers_test.go

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package tgbotapi_test
2+
3+
import (
4+
"github.com/go-telegram-bot-api/telegram-bot-api"
5+
"testing"
6+
)
7+
8+
func 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+
19+
func 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+
29+
func 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+
39+
func 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+
49+
func 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+
}
56+
}
57+
58+
func TestNewInlineQueryResultAudio(t *testing.T) {
59+
result := tgbotapi.NewInlineQueryResultAudio("id", "google.com", "title")
60+
61+
if result.Type != "audio" ||
62+
result.ID != "id" ||
63+
result.URL != "google.com" ||
64+
result.Title != "title" {
65+
}
66+
}
67+
68+
func TestNewInlineQueryResultVoice(t *testing.T) {
69+
result := tgbotapi.NewInlineQueryResultVoice("id", "google.com", "title")
70+
71+
if result.Type != "voice" ||
72+
result.ID != "id" ||
73+
result.URL != "google.com" ||
74+
result.Title != "title" {
75+
}
76+
}
77+
78+
func TestNewInlineQueryResultDocument(t *testing.T) {
79+
result := tgbotapi.NewInlineQueryResultDocument("id", "google.com", "title", "mime/type")
80+
81+
if result.Type != "document" ||
82+
result.ID != "id" ||
83+
result.URL != "google.com" ||
84+
result.Title != "title" ||
85+
result.MimeType != "mime/type" {
86+
}
87+
}
88+
89+
func TestNewInlineQueryResultLocation(t *testing.T) {
90+
result := tgbotapi.NewInlineQueryResultLocation("id", "name", 40, 50)
91+
92+
if result.Type != "location" ||
93+
result.ID != "id" ||
94+
result.Title != "name" ||
95+
result.Latitude != 40 ||
96+
result.Longitude != 50 {
97+
}
98+
}
99+
100+
func TestNewEditMessageText(t *testing.T) {
101+
edit := tgbotapi.NewEditMessageText(ChatID, ReplyToMessageID, "new text")
102+
103+
if edit.Text != "new text" ||
104+
edit.BaseEdit.ChatID != ChatID ||
105+
edit.BaseEdit.MessageID != ReplyToMessageID {
106+
t.Fail()
107+
}
108+
}
109+
110+
func TestNewEditMessageCaption(t *testing.T) {
111+
edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption")
112+
113+
if edit.Caption != "new caption" ||
114+
edit.BaseEdit.ChatID != ChatID ||
115+
edit.BaseEdit.MessageID != ReplyToMessageID {
116+
t.Fail()
117+
}
118+
}
119+
120+
func TestNewEditMessageReplyMarkup(t *testing.T) {
121+
markup := tgbotapi.InlineKeyboardMarkup{
122+
InlineKeyboard: [][]tgbotapi.InlineKeyboardButton{
123+
[]tgbotapi.InlineKeyboardButton{
124+
tgbotapi.InlineKeyboardButton{Text: "test"},
125+
},
126+
},
127+
}
128+
129+
edit := tgbotapi.NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup)
130+
131+
if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" ||
132+
edit.BaseEdit.ChatID != ChatID ||
133+
edit.BaseEdit.MessageID != ReplyToMessageID {
134+
t.Fail()
135+
}
136+
137+
}

0 commit comments

Comments
 (0)