2016-04-08 16:18:34 +00:00
|
|
|
package fact
|
|
|
|
|
|
|
|
import (
|
2019-05-27 23:21:53 +00:00
|
|
|
"github.com/velour/catbase/plugins/cli"
|
2016-04-08 16:18:34 +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
|
|
|
var c = &cli.CliPlugin{}
|
|
|
|
|
2016-04-08 16:18:34 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 18:22:54 +00:00
|
|
|
func makePlugin(t *testing.T) (*FactoidPlugin, *bot.MockBot) {
|
2016-04-08 16:18:34 +00:00
|
|
|
mb := bot.NewMockBot()
|
|
|
|
f := New(mb) // for DB table
|
2019-02-15 18:22:54 +00:00
|
|
|
return f, mb
|
2016-04-08 16:18:34 +00:00
|
|
|
}
|
2019-01-20 17:33:19 +00:00
|
|
|
|
|
|
|
func TestReact(t *testing.T) {
|
|
|
|
msgs := []msg.Message{
|
|
|
|
makeMessage("user1", "!testing123 <react> jesus"),
|
|
|
|
makeMessage("user2", "testing123"),
|
|
|
|
}
|
2019-02-15 18:22:54 +00:00
|
|
|
p, mb := makePlugin(t)
|
2019-01-20 17:33:19 +00:00
|
|
|
|
|
|
|
for _, m := range msgs {
|
2019-05-27 23:21:53 +00:00
|
|
|
p.message(c, bot.Message, m)
|
2019-01-20 17:33:19 +00:00
|
|
|
}
|
|
|
|
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"),
|
|
|
|
}
|
2019-02-15 18:22:54 +00:00
|
|
|
p, mb := makePlugin(t)
|
2019-01-20 17:33:19 +00:00
|
|
|
|
|
|
|
for _, m := range msgs {
|
2019-05-27 23:21:53 +00:00
|
|
|
p.message(c, bot.Message, m)
|
2019-01-20 17:33:19 +00:00
|
|
|
}
|
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
assert.Contains(t, mb.Messages[0], "not a valid")
|
|
|
|
}
|