catbase/plugins/twitch/twitch_test.go

51 lines
1.2 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"
)
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) (*TwitchPlugin, *bot.MockBot) {
mb := bot.NewMockBot()
c := New(mb)
2019-01-22 00:16:57 +00:00
mb.Config().Set("twitch.clientid", "fake")
mb.Config().Set("twitch.authorization", "fake")
c.config.SetArray("Twitch.Channels", []string{"test"})
c.config.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)
2019-02-05 20:02:15 +00:00
b.message(makeMessage("!twitch status"))
2016-08-09 00:44:28 +00:00
assert.NotEmpty(t, mb.Messages)
}