all repos — telegram-bot-api @ 06d94aeeed6cc221e7ed93b2c085af79e1c8cd39

Golang bindings for the Telegram Bot API

types_test.go (view raw)

 1package tgbotapi_test
 2
 3import (
 4	"github.com/Syfaro/telegram-bot-api"
 5	"testing"
 6	"time"
 7)
 8
 9func TestUserStringWith(t *testing.T) {
10	user := tgbotapi.User{0, "Test", "Test", ""}
11
12	if user.String() != "Test Test" {
13		t.Fail()
14	}
15}
16
17func TestUserStringWithUserName(t *testing.T) {
18	user := tgbotapi.User{0, "Test", "Test", "@test"}
19
20	if user.String() != "@test" {
21		t.Fail()
22	}
23}
24
25func TestMessageIsGroup(t *testing.T) {
26	from := tgbotapi.User{ID: 0}
27	chat := tgbotapi.Chat{ID: 10}
28	message := tgbotapi.Message{From: from, Chat: chat}
29
30	if message.IsGroup() != true {
31		t.Fail()
32	}
33}
34
35func TestMessageTime(t *testing.T) {
36	message := tgbotapi.Message{Date: 0}
37
38	date := time.Unix(0, 0)
39	if message.Time() != date {
40		t.Fail()
41	}
42}
43
44func TestChatIsPrivate(t *testing.T) {
45	chat := tgbotapi.Chat{ID: 10, Type: "private"}
46
47	if chat.IsPrivate() != true {
48		t.Fail()
49	}
50}
51
52func TestChatIsGroup(t *testing.T) {
53	chat := tgbotapi.Chat{ID: 10, Type: "group"}
54
55	if chat.IsGroup() != true {
56		t.Fail()
57	}
58}
59
60func TestChatIsChannel(t *testing.T) {
61	chat := tgbotapi.Chat{ID: 10, Type: "channel"}
62
63	if chat.IsChannel() != true {
64		t.Fail()
65	}
66}
67
68func TestFileLink(t *testing.T) {
69	file := tgbotapi.File{FilePath: "test/test.txt"}
70
71	if file.Link("token") != "https://api.telegram.org/file/bottoken/test/test.txt" {
72		t.Fail()
73	}
74}