240 lines
5.1 KiB
Go
240 lines
5.1 KiB
Go
package tgbotapi
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestUserStringWith(t *testing.T) {
|
|
user := User{
|
|
ID: 0,
|
|
FirstName: "Test",
|
|
LastName: "Test",
|
|
UserName: "",
|
|
LanguageCode: "en",
|
|
IsBot: false,
|
|
}
|
|
|
|
if user.String() != "Test Test" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestUserStringWithUserName(t *testing.T) {
|
|
user := User{
|
|
ID: 0,
|
|
FirstName: "Test",
|
|
LastName: "Test",
|
|
UserName: "@test",
|
|
LanguageCode: "en",
|
|
}
|
|
|
|
if user.String() != "@test" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestMessageTime(t *testing.T) {
|
|
message := Message{Date: 0}
|
|
|
|
date := time.Unix(0, 0)
|
|
if message.Time() != date {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestMessageIsCommandWithCommand(t *testing.T) {
|
|
message := Message{Text: "/command"}
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
|
|
|
if !message.IsCommand() {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestIsCommandWithText(t *testing.T) {
|
|
message := Message{Text: "some text"}
|
|
|
|
if message.IsCommand() {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestIsCommandWithEmptyText(t *testing.T) {
|
|
message := Message{Text: ""}
|
|
|
|
if message.IsCommand() {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestCommandWithCommand(t *testing.T) {
|
|
message := Message{Text: "/command"}
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
|
|
|
if message.Command() != "command" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestCommandWithEmptyText(t *testing.T) {
|
|
message := Message{Text: ""}
|
|
|
|
if message.Command() != "" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestCommandWithNonCommand(t *testing.T) {
|
|
message := Message{Text: "test text"}
|
|
|
|
if message.Command() != "" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestCommandWithBotName(t *testing.T) {
|
|
message := Message{Text: "/command@testbot"}
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
|
|
|
if message.Command() != "command" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestCommandWithAtWithBotName(t *testing.T) {
|
|
message := Message{Text: "/command@testbot"}
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
|
|
|
if message.CommandWithAt() != "command@testbot" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestMessageCommandArgumentsWithArguments(t *testing.T) {
|
|
message := Message{Text: "/command with arguments"}
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
|
if message.CommandArguments() != "with arguments" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestMessageCommandArgumentsWithMalformedArguments(t *testing.T) {
|
|
message := Message{Text: "/command-without argument space"}
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
|
if message.CommandArguments() != "without argument space" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestMessageCommandArgumentsWithoutArguments(t *testing.T) {
|
|
message := Message{Text: "/command"}
|
|
if message.CommandArguments() != "" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestMessageCommandArgumentsForNonCommand(t *testing.T) {
|
|
message := Message{Text: "test text"}
|
|
if message.CommandArguments() != "" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestMessageEntityParseURLGood(t *testing.T) {
|
|
entity := MessageEntity{URL: "https://www.google.com"}
|
|
|
|
if _, err := entity.ParseURL(); err != nil {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestMessageEntityParseURLBad(t *testing.T) {
|
|
entity := MessageEntity{URL: ""}
|
|
|
|
if _, err := entity.ParseURL(); err == nil {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestChatIsPrivate(t *testing.T) {
|
|
chat := Chat{ID: 10, Type: "private"}
|
|
|
|
if !chat.IsPrivate() {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestChatIsGroup(t *testing.T) {
|
|
chat := Chat{ID: 10, Type: "group"}
|
|
|
|
if !chat.IsGroup() {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestChatIsChannel(t *testing.T) {
|
|
chat := Chat{ID: 10, Type: "channel"}
|
|
|
|
if !chat.IsChannel() {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestChatIsSuperGroup(t *testing.T) {
|
|
chat := Chat{ID: 10, Type: "supergroup"}
|
|
|
|
if !chat.IsSuperGroup() {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestFileLink(t *testing.T) {
|
|
file := File{FilePath: "test/test.txt"}
|
|
|
|
if file.Link("token") != "https://api.telegram.org/file/bottoken/test/test.txt" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
// Ensure all configs are sendable
|
|
var (
|
|
_ Chattable = AnimationConfig{}
|
|
_ Chattable = AudioConfig{}
|
|
_ Chattable = CallbackConfig{}
|
|
_ Chattable = ChatActionConfig{}
|
|
_ Chattable = ContactConfig{}
|
|
_ Chattable = DeleteChatPhotoConfig{}
|
|
_ Chattable = DeleteChatStickerSetConfig{}
|
|
_ Chattable = DeleteMessageConfig{}
|
|
_ Chattable = DocumentConfig{}
|
|
_ Chattable = EditMessageCaptionConfig{}
|
|
_ Chattable = EditMessageLiveLocationConfig{}
|
|
_ Chattable = EditMessageReplyMarkupConfig{}
|
|
_ Chattable = EditMessageTextConfig{}
|
|
_ Chattable = ForwardConfig{}
|
|
_ Chattable = GameConfig{}
|
|
_ Chattable = GetGameHighScoresConfig{}
|
|
_ Chattable = InlineConfig{}
|
|
_ Chattable = InvoiceConfig{}
|
|
_ Chattable = KickChatMemberConfig{}
|
|
_ Chattable = LocationConfig{}
|
|
_ Chattable = MediaGroupConfig{}
|
|
_ Chattable = MessageConfig{}
|
|
_ Chattable = PhotoConfig{}
|
|
_ Chattable = PinChatMessageConfig{}
|
|
_ Chattable = SetChatDescriptionConfig{}
|
|
_ Chattable = SetChatPhotoConfig{}
|
|
_ Chattable = SetChatTitleConfig{}
|
|
_ Chattable = SetGameScoreConfig{}
|
|
_ Chattable = StickerConfig{}
|
|
_ Chattable = UnpinChatMessageConfig{}
|
|
_ Chattable = UpdateConfig{}
|
|
_ Chattable = UserProfilePhotosConfig{}
|
|
_ Chattable = VenueConfig{}
|
|
_ Chattable = VideoConfig{}
|
|
_ Chattable = VideoNoteConfig{}
|
|
_ Chattable = VoiceConfig{}
|
|
_ Chattable = WebhookConfig{}
|
|
)
|