catbase/plugins/talker/talker_test.go

91 lines
2.0 KiB
Go
Raw Normal View History

2016-03-30 23:25:02 +00:00
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
package talker
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/bot/user"
2016-03-30 23:25:02 +00:00
)
2019-02-05 20:02:15 +00:00
func makeMessage(payload string) (bot.Kind, msg.Message) {
2016-03-30 23:25:02 +00:00
isCmd := strings.HasPrefix(payload, "!")
if isCmd {
payload = payload[1:]
}
2019-02-05 20:02:15 +00:00
return bot.Message, msg.Message{
User: &user.User{Name: "tester"},
2016-03-30 23:25:02 +00:00
Channel: "test",
Body: payload,
Command: isCmd,
}
}
func TestGoatse(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("goatse"))
2016-03-30 23:25:02 +00:00
assert.Len(t, mb.Messages, 0)
assert.False(t, res)
}
func TestGoatseCommand(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!goatse"))
2016-03-30 23:25:02 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "g o a t s e")
}
func TestGoatseWithNickCommand(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!goatse seabass"))
2016-03-30 23:25:02 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "g o a t s e")
assert.Contains(t, mb.Messages[0], "seabass")
}
func TestSay(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("say hello"))
2016-03-30 23:25:02 +00:00
assert.Len(t, mb.Messages, 0)
assert.False(t, res)
}
func TestSayCommand(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!say hello"))
2016-03-30 23:25:02 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "hello")
}
func TestHelp(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
c.help(bot.Help, msg.Message{Channel: "channel"}, []string{})
2016-03-30 23:25:02 +00:00
assert.Len(t, mb.Messages, 1)
}
func TestRegisterWeb(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
assert.Nil(t, c.RegisterWeb())
}