catbase/plugins/fact/fact_test.go

61 lines
1.2 KiB
Go
Raw Normal View History

package fact
import (
2019-05-27 23:21:53 +00:00
"github.com/velour/catbase/plugins/cli"
"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
var c = &cli.CliPlugin{}
func makeMessage(nick, payload string) msg.Message {
isCmd := strings.HasPrefix(payload, "!")
if isCmd {
payload = payload[1:]
}
return msg.Message{
User: &user.User{Name: nick},
Channel: "test",
Body: payload,
Command: isCmd,
}
}
func makePlugin(t *testing.T) (*FactoidPlugin, *bot.MockBot) {
mb := bot.NewMockBot()
f := New(mb) // for DB table
return f, mb
}
func TestReact(t *testing.T) {
msgs := []msg.Message{
makeMessage("user1", "!testing123 <react> jesus"),
makeMessage("user2", "testing123"),
}
p, mb := makePlugin(t)
for _, m := range msgs {
2019-05-27 23:21:53 +00:00
p.message(c, bot.Message, m)
}
assert.Len(t, mb.Reactions, 1)
assert.Contains(t, mb.Reactions[0], "jesus")
}
func TestReactCantLearnSpaces(t *testing.T) {
msgs := []msg.Message{
makeMessage("user1", "!test <react> jesus christ"),
}
p, mb := makePlugin(t)
for _, m := range msgs {
2019-05-27 23:21:53 +00:00
p.message(c, bot.Message, m)
}
assert.Len(t, mb.Messages, 1)
assert.Contains(t, mb.Messages[0], "not a valid")
}