-
Notifications
You must be signed in to change notification settings - Fork 15
/
authorization_test.go
43 lines (32 loc) · 1.07 KB
/
authorization_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
package margelet_test
import (
"testing"
"time"
"../margelet"
. "github.com/smartystreets/goconvey/convey"
"gopkg.in/telegram-bot-api.v4"
)
func TestAuthorization(t *testing.T) {
Convey("When given margelet", t, func() {
m := getMargelet()
Convey("with registered command with auth policy", func() {
m.AddCommandHandler("/test", margelet.HelpHandler{}, margelet.UsernameAuthorizationPolicy{Usernames: []string{"test"}})
Convey("sending message from allowed user", func() {
from := tgbotapi.User{UserName: "test"}
chat := tgbotapi.Chat{ID: 1}
go m.Run()
botMock.Updates <- tgbotapi.Update{Message: &tgbotapi.Message{From: &from, Text: "/test", Chat: &chat}}
time.Sleep(100 * time.Millisecond)
m.Stop()
})
Convey("sending message from disallowed user", func() {
from := tgbotapi.User{UserName: "another_user"}
chat := tgbotapi.Chat{ID: 1}
go m.Run()
botMock.Updates <- tgbotapi.Update{Message: &tgbotapi.Message{From: &from, Text: "/test", Chat: &chat}}
time.Sleep(100 * time.Millisecond)
m.Stop()
})
})
})
}