This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsystem_test.go
94 lines (80 loc) · 2.38 KB
/
system_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
package dcmd
import (
"fmt"
"github.com/jonas747/discordgo"
"github.com/stretchr/testify/assert"
"testing"
)
const (
TestUserID = 105487308693757952
TestUserIDStr = "105487308693757952"
)
var (
testSystem *System
testSession *discordgo.Session
)
type TestCommand struct{}
const (
TestResponse = "Test Response"
)
func (e *TestCommand) ShortDescription() string { return "Test Description" }
func (e *TestCommand) Run(data *Data) (interface{}, error) {
return TestResponse, nil
}
func SetupTestSystem() {
testSystem = NewStandardSystem("!")
testSystem.Root.AddCommand(&TestCommand{}, NewTrigger("test"))
testSession = &discordgo.Session{
State: &discordgo.State{
Ready: discordgo.Ready{
User: &discordgo.SelfUser{
User: &discordgo.User{
ID: TestUserID,
},
},
},
},
}
}
func TestFindPrefix(t *testing.T) {
testChannelNoPriv := &discordgo.Channel{
Type: discordgo.ChannelTypeGuildText,
}
testChannelPriv := &discordgo.Channel{
Type: discordgo.ChannelTypeDM,
}
cases := []struct {
channel *discordgo.Channel
msgContent string
expectedStripped string
shouldBeFound bool
expectedSource TriggerSource
mentions []*discordgo.User
}{
{testChannelNoPriv, "!cmd", "cmd", true, PrefixSource, nil},
{testChannelNoPriv, "cmd", "cmd", false, PrefixSource, nil},
{testChannelNoPriv, "<@" + TestUserIDStr + ">cmd", "cmd", true, MentionSource, []*discordgo.User{&discordgo.User{ID: TestUserID}}},
{testChannelNoPriv, "<@" + TestUserIDStr + "> cmd", "cmd", true, MentionSource, []*discordgo.User{&discordgo.User{ID: TestUserID}}},
{testChannelNoPriv, "<@" + TestUserIDStr + " cmd", "", false, MentionSource, nil},
{testChannelPriv, "cmd", "cmd", true, DMSource, nil},
}
for k, v := range cases {
t.Run(fmt.Sprintf("#%d-p:%v-m:%v", k, v.channel == testChannelPriv, v.shouldBeFound), func(t *testing.T) {
testData := &Data{
Session: testSession,
// Channel: v.channel,
Msg: &discordgo.Message{
Content: v.msgContent,
Mentions: v.mentions,
},
}
found := testSystem.FindPrefix(testData)
assert.Equal(t, v.shouldBeFound, found, "Should match test case")
if !found {
return
}
assert.Equal(t, v.expectedStripped, testData.MsgStrippedPrefix, "Should be stripped off of prefix correctly")
assert.Equal(t, v.expectedSource, testData.Source, "Should have the proper prefix")
})
}
}