forked from requilence/integram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tgupdates_test.go
181 lines (177 loc) · 6.76 KB
/
tgupdates_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package integram
import (
"testing"
"time"
tg "github.com/requilence/telegram-bot-api"
)
func TestIncomingMessage_IsEventBotAddedToGroup(t *testing.T) {
type fields struct {
Message Message
From User
Chat Chat
ForwardFrom *User
ForwardDate time.Time
ReplyToMessage *Message
ForwardFromChat *Chat
EditDate int
Entities *[]tg.MessageEntity
Audio *tg.Audio
Document *tg.Document
Photo *[]tg.PhotoSize
Sticker *tg.Sticker
Video *tg.Video
Voice *tg.Voice
Caption string
Contact *tg.Contact
Location *tg.Location
Venue *tg.Venue
NewChatMember []*User
LeftChatMember *User
NewChatTitle string
NewChatPhoto *[]tg.PhotoSize
DeleteChatPhoto bool
GroupChatCreated bool
SuperGroupChatCreated bool
ChannelChatCreated bool
MigrateToChatID int64
MigrateFromChatID int64
PinnedMessage *Message
needToUpdateDB bool
}
tests := []struct {
name string
fields fields
want bool
}{
{"NewChatMember with user equal to bot", fields{Message: Message{BotID: 12345}, NewChatMember: []*User{&User{ID: 12345}}}, true},
{"NewChatMember with user not equal to bot", fields{Message: Message{BotID: 123456}, NewChatMember: []*User{&User{ID: 12345}}}, false},
{"GroupChatCreated with user not equal to bot", fields{Message: Message{BotID: 123456}, GroupChatCreated: true}, true},
{"NewChatMember with user not equal to bot", fields{Message: Message{BotID: 123456}, SuperGroupChatCreated: true}, true},
}
for _, tt := range tests {
m := &IncomingMessage{
Message: tt.fields.Message,
From: tt.fields.From,
Chat: tt.fields.Chat,
ForwardFrom: tt.fields.ForwardFrom,
ForwardDate: tt.fields.ForwardDate,
ReplyToMessage: tt.fields.ReplyToMessage,
ForwardFromChat: tt.fields.ForwardFromChat,
EditDate: tt.fields.EditDate,
Entities: tt.fields.Entities,
Audio: tt.fields.Audio,
Document: tt.fields.Document,
Photo: tt.fields.Photo,
Sticker: tt.fields.Sticker,
Video: tt.fields.Video,
Voice: tt.fields.Voice,
Caption: tt.fields.Caption,
Contact: tt.fields.Contact,
Location: tt.fields.Location,
Venue: tt.fields.Venue,
NewChatMembers: tt.fields.NewChatMember,
LeftChatMember: tt.fields.LeftChatMember,
NewChatTitle: tt.fields.NewChatTitle,
NewChatPhoto: tt.fields.NewChatPhoto,
DeleteChatPhoto: tt.fields.DeleteChatPhoto,
GroupChatCreated: tt.fields.GroupChatCreated,
SuperGroupChatCreated: tt.fields.SuperGroupChatCreated,
ChannelChatCreated: tt.fields.ChannelChatCreated,
MigrateToChatID: tt.fields.MigrateToChatID,
MigrateFromChatID: tt.fields.MigrateFromChatID,
PinnedMessage: tt.fields.PinnedMessage,
needToUpdateDB: tt.fields.needToUpdateDB,
}
if got := m.IsEventBotAddedToGroup(); got != tt.want {
t.Errorf("%q. IncomingMessage.IsEventBotAddedToGroup() = %v, want %v", tt.name, got, tt.want)
}
}
}
func TestIncomingMessage_GetCommand(t *testing.T) {
type fields struct {
Message Message
From User
Chat Chat
ForwardFrom *User
ForwardDate time.Time
ReplyToMessage *Message
ForwardFromChat *Chat
EditDate int
Entities *[]tg.MessageEntity
Audio *tg.Audio
Document *tg.Document
Photo *[]tg.PhotoSize
Sticker *tg.Sticker
Video *tg.Video
Voice *tg.Voice
Caption string
Contact *tg.Contact
Location *tg.Location
Venue *tg.Venue
NewChatMembers []*User
LeftChatMember *User
NewChatTitle string
NewChatPhoto *[]tg.PhotoSize
DeleteChatPhoto bool
GroupChatCreated bool
SuperGroupChatCreated bool
ChannelChatCreated bool
MigrateToChatID int64
MigrateFromChatID int64
PinnedMessage *Message
needToUpdateDB bool
}
tests := []struct {
name string
fields fields
want string
want1 string
}{
{"just command", fields{Message: Message{Text: "/command123"}}, "command123", ""},
{"command with param", fields{Message: Message{Text: "/command123 param"}}, "command123", "param"},
{"command with bot name", fields{Message: Message{Text: "/command123@bot"}}, "command123", ""},
{"command with bot name and param", fields{Message: Message{Text: "/command123@bot param"}}, "command123", "param"},
}
for _, tt := range tests {
m := &IncomingMessage{
Message: tt.fields.Message,
From: tt.fields.From,
Chat: tt.fields.Chat,
ForwardFrom: tt.fields.ForwardFrom,
ForwardDate: tt.fields.ForwardDate,
ReplyToMessage: tt.fields.ReplyToMessage,
ForwardFromChat: tt.fields.ForwardFromChat,
EditDate: tt.fields.EditDate,
Entities: tt.fields.Entities,
Audio: tt.fields.Audio,
Document: tt.fields.Document,
Photo: tt.fields.Photo,
Sticker: tt.fields.Sticker,
Video: tt.fields.Video,
Voice: tt.fields.Voice,
Caption: tt.fields.Caption,
Contact: tt.fields.Contact,
Location: tt.fields.Location,
Venue: tt.fields.Venue,
NewChatMembers: tt.fields.NewChatMembers,
LeftChatMember: tt.fields.LeftChatMember,
NewChatTitle: tt.fields.NewChatTitle,
NewChatPhoto: tt.fields.NewChatPhoto,
DeleteChatPhoto: tt.fields.DeleteChatPhoto,
GroupChatCreated: tt.fields.GroupChatCreated,
SuperGroupChatCreated: tt.fields.SuperGroupChatCreated,
ChannelChatCreated: tt.fields.ChannelChatCreated,
MigrateToChatID: tt.fields.MigrateToChatID,
MigrateFromChatID: tt.fields.MigrateFromChatID,
PinnedMessage: tt.fields.PinnedMessage,
needToUpdateDB: tt.fields.needToUpdateDB,
}
got, got1 := m.GetCommand()
if got != tt.want {
t.Errorf("%q. IncomingMessage.GetCommand() got = %v, want %v", tt.name, got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("%q. IncomingMessage.GetCommand() got1 = %v, want %v", tt.name, got1, tt.want1)
}
}
}