From e7b9f16e73b8f9d5ba62cc4b0736d493bf72e1d1 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Thu, 14 Apr 2016 14:00:45 -0500 Subject: [PATCH] Add missing helpers, move helper tests to own file. --- bot_test.go | 89 ------------------------------- helpers.go | 42 +++++++++++++++ helpers_test.go | 137 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 89 deletions(-) create mode 100644 helpers_test.go diff --git a/bot_test.go b/bot_test.go index 5fb9b31..dbe40a9 100644 --- a/bot_test.go +++ b/bot_test.go @@ -419,95 +419,6 @@ func TestSetWebhookWithoutCert(t *testing.T) { bot.RemoveWebhook() } -func TestNewInlineQueryResultArticle(t *testing.T) { - result := tgbotapi.NewInlineQueryResultArticle("id", "title", "message") - - if result.Type != "article" || - result.ID != "id" || - result.Title != "title" || - result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "message" { - t.Fail() - } -} - -func TestNewInlineQueryResultGIF(t *testing.T) { - result := tgbotapi.NewInlineQueryResultGIF("id", "google.com") - - if result.Type != "gif" || - result.ID != "id" || - result.URL != "google.com" { - t.Fail() - } -} - -func TestNewInlineQueryResultMPEG4GIF(t *testing.T) { - result := tgbotapi.NewInlineQueryResultMPEG4GIF("id", "google.com") - - if result.Type != "mpeg4_gif" || - result.ID != "id" || - result.URL != "google.com" { - t.Fail() - } -} - -func TestNewInlineQueryResultPhoto(t *testing.T) { - result := tgbotapi.NewInlineQueryResultPhoto("id", "google.com") - - if result.Type != "photo" || - result.ID != "id" || - result.URL != "google.com" { - t.Fail() - } -} - -func TestNewInlineQueryResultVideo(t *testing.T) { - result := tgbotapi.NewInlineQueryResultVideo("id", "google.com") - - if result.Type != "video" || - result.ID != "id" || - result.URL != "google.com" { - } -} - -func TestNewEditMessageText(t *testing.T) { - edit := tgbotapi.NewEditMessageText(ChatID, ReplyToMessageID, "new text") - - if edit.Text != "new text" || - edit.BaseEdit.ChatID != ChatID || - edit.BaseEdit.MessageID != ReplyToMessageID { - t.Fail() - } -} - -func TestNewEditMessageCaption(t *testing.T) { - edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption") - - if edit.Caption != "new caption" || - edit.BaseEdit.ChatID != ChatID || - edit.BaseEdit.MessageID != ReplyToMessageID { - t.Fail() - } -} - -func TestNewEditMessageReplyMarkup(t *testing.T) { - markup := tgbotapi.InlineKeyboardMarkup{ - InlineKeyboard: [][]tgbotapi.InlineKeyboardButton{ - []tgbotapi.InlineKeyboardButton{ - tgbotapi.InlineKeyboardButton{Text: "test"}, - }, - }, - } - - edit := tgbotapi.NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup) - - if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" || - edit.BaseEdit.ChatID != ChatID || - edit.BaseEdit.MessageID != ReplyToMessageID { - t.Fail() - } - -} - func TestUpdatesChan(t *testing.T) { bot, _ := getBot(t) diff --git a/helpers.go b/helpers.go index e1c5f54..73280cb 100644 --- a/helpers.go +++ b/helpers.go @@ -352,6 +352,48 @@ func NewInlineQueryResultVideo(id, url string) InlineQueryResultVideo { } } +// NewInlineQueryResultAudio creates a new inline query audio. +func NewInlineQueryResultAudio(id, url, title string) InlineQueryResultAudio { + return InlineQueryResultAudio{ + Type: "audio", + ID: id, + URL: url, + Title: title, + } +} + +// NewInlineQueryResultVoice creates a new inline query voice. +func NewInlineQueryResultVoice(id, url, title string) InlineQueryResultVoice { + return InlineQueryResultVoice{ + Type: "voice", + ID: id, + URL: url, + Title: title, + } +} + +// NewInlineQueryResultDocument creates a new inline query document. +func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryResultDocument { + return InlineQueryResultDocument{ + Type: "document", + ID: id, + URL: url, + Title: title, + MimeType: mimeType, + } +} + +// NewInlineQueryResultLocation creates a new inline query location. +func NewInlineQueryResultLocation(id, title string, latitude, longitude float64) InlineQueryResultLocation { + return InlineQueryResultLocation{ + Type: "location", + ID: id, + Title: title, + Latitude: latitude, + Longitude: longitude, + } +} + // NewEditMessageText allows you to edit the text of a message. func NewEditMessageText(chatID int64, messageID int, text string) EditMessageTextConfig { return EditMessageTextConfig{ diff --git a/helpers_test.go b/helpers_test.go new file mode 100644 index 0000000..747c126 --- /dev/null +++ b/helpers_test.go @@ -0,0 +1,137 @@ +package tgbotapi_test + +import ( + "github.com/go-telegram-bot-api/telegram-bot-api" + "testing" +) + +func TestNewInlineQueryResultArticle(t *testing.T) { + result := tgbotapi.NewInlineQueryResultArticle("id", "title", "message") + + if result.Type != "article" || + result.ID != "id" || + result.Title != "title" || + result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "message" { + t.Fail() + } +} + +func TestNewInlineQueryResultGIF(t *testing.T) { + result := tgbotapi.NewInlineQueryResultGIF("id", "google.com") + + if result.Type != "gif" || + result.ID != "id" || + result.URL != "google.com" { + t.Fail() + } +} + +func TestNewInlineQueryResultMPEG4GIF(t *testing.T) { + result := tgbotapi.NewInlineQueryResultMPEG4GIF("id", "google.com") + + if result.Type != "mpeg4_gif" || + result.ID != "id" || + result.URL != "google.com" { + t.Fail() + } +} + +func TestNewInlineQueryResultPhoto(t *testing.T) { + result := tgbotapi.NewInlineQueryResultPhoto("id", "google.com") + + if result.Type != "photo" || + result.ID != "id" || + result.URL != "google.com" { + t.Fail() + } +} + +func TestNewInlineQueryResultVideo(t *testing.T) { + result := tgbotapi.NewInlineQueryResultVideo("id", "google.com") + + if result.Type != "video" || + result.ID != "id" || + result.URL != "google.com" { + } +} + +func TestNewInlineQueryResultAudio(t *testing.T) { + result := tgbotapi.NewInlineQueryResultAudio("id", "google.com", "title") + + if result.Type != "audio" || + result.ID != "id" || + result.URL != "google.com" || + result.Title != "title" { + } +} + +func TestNewInlineQueryResultVoice(t *testing.T) { + result := tgbotapi.NewInlineQueryResultVoice("id", "google.com", "title") + + if result.Type != "voice" || + result.ID != "id" || + result.URL != "google.com" || + result.Title != "title" { + } +} + +func TestNewInlineQueryResultDocument(t *testing.T) { + result := tgbotapi.NewInlineQueryResultDocument("id", "google.com", "title", "mime/type") + + if result.Type != "document" || + result.ID != "id" || + result.URL != "google.com" || + result.Title != "title" || + result.MimeType != "mime/type" { + } +} + +func TestNewInlineQueryResultLocation(t *testing.T) { + result := tgbotapi.NewInlineQueryResultLocation("id", "name", 40, 50) + + if result.Type != "location" || + result.ID != "id" || + result.Title != "name" || + result.Latitude != 40 || + result.Longitude != 50 { + } +} + +func TestNewEditMessageText(t *testing.T) { + edit := tgbotapi.NewEditMessageText(ChatID, ReplyToMessageID, "new text") + + if edit.Text != "new text" || + edit.BaseEdit.ChatID != ChatID || + edit.BaseEdit.MessageID != ReplyToMessageID { + t.Fail() + } +} + +func TestNewEditMessageCaption(t *testing.T) { + edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption") + + if edit.Caption != "new caption" || + edit.BaseEdit.ChatID != ChatID || + edit.BaseEdit.MessageID != ReplyToMessageID { + t.Fail() + } +} + +func TestNewEditMessageReplyMarkup(t *testing.T) { + markup := tgbotapi.InlineKeyboardMarkup{ + InlineKeyboard: [][]tgbotapi.InlineKeyboardButton{ + []tgbotapi.InlineKeyboardButton{ + tgbotapi.InlineKeyboardButton{Text: "test"}, + }, + }, + } + + edit := tgbotapi.NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup) + + if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" || + edit.BaseEdit.ChatID != ChatID || + edit.BaseEdit.MessageID != ReplyToMessageID { + t.Fail() + } + +}