catbase/plugins/twitch/twitch_test.go

62 lines
1.3 KiB
Go
Raw Normal View History

2016-08-09 00:44:28 +00:00
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
package twitch
import (
2019-05-27 23:21:53 +00:00
"github.com/velour/catbase/plugins/cli"
2016-08-09 00:44:28 +00:00
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/bot/user"
)
func makeRequest(payload string) bot.Request {
c, k, m := makeMessage(payload)
return bot.Request{
Conn: c,
Kind: k,
Msg: m,
Values: nil,
Args: nil,
}
}
2019-05-27 23:21:53 +00:00
func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) {
2016-08-09 00:44:28 +00:00
isCmd := strings.HasPrefix(payload, "!")
if isCmd {
payload = payload[1:]
}
2019-05-27 23:21:53 +00:00
return &cli.CliPlugin{}, bot.Message, msg.Message{
2016-08-09 00:44:28 +00:00
User: &user.User{Name: "tester"},
Channel: "test",
Body: payload,
Command: isCmd,
}
}
func makeTwitchPlugin(t *testing.T) (*Twitch, *bot.MockBot) {
2016-08-09 00:44:28 +00:00
mb := bot.NewMockBot()
c := New(mb)
2019-01-22 00:16:57 +00:00
mb.Config().Set("twitch.clientid", "fake")
2022-08-31 17:20:16 +00:00
mb.Config().Set("twitch.secret", "fake")
c.c.SetArray("Twitch.Channels", []string{"test"})
c.c.SetArray("Twitch.test.Users", []string{"drseabass"})
2016-08-09 00:44:28 +00:00
assert.NotNil(t, c)
c.twitchList["drseabass"] = &Twitcher{
2019-02-06 02:13:35 +00:00
name: "drseabass",
gameID: "",
2016-08-09 00:44:28 +00:00
}
return c, mb
}
func TestTwitch(t *testing.T) {
b, mb := makeTwitchPlugin(t)
b.twitchStatus(makeRequest("!twitch status"))
2016-08-09 00:44:28 +00:00
assert.NotEmpty(t, mb.Messages)
}