2019-01-19 00:48:12 +00:00
|
|
|
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
|
|
|
|
|
|
|
package nerdepedia
|
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2019-02-05 20:02:15 +00:00
|
|
|
func makeMessage(payload string) (bot.Kind, msg.Message) {
|
2019-01-19 00:48:12 +00:00
|
|
|
isCmd := strings.HasPrefix(payload, "!")
|
|
|
|
if isCmd {
|
|
|
|
payload = payload[1:]
|
|
|
|
}
|
2019-02-05 20:02:15 +00:00
|
|
|
return bot.Message, msg.Message{
|
2019-01-19 00:48:12 +00:00
|
|
|
User: &user.User{Name: "tester"},
|
|
|
|
Channel: "test",
|
|
|
|
Body: payload,
|
|
|
|
Command: isCmd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-19 16:06:13 +00:00
|
|
|
func TestWars(t *testing.T) {
|
2019-01-19 00:48:12 +00:00
|
|
|
mb := bot.NewMockBot()
|
|
|
|
c := New(mb)
|
|
|
|
assert.NotNil(t, c)
|
2019-02-05 20:02:15 +00:00
|
|
|
res := c.message(makeMessage("help me obi-wan"))
|
2019-01-19 00:48:12 +00:00
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
assert.True(t, res)
|
|
|
|
}
|
2019-01-19 16:06:13 +00:00
|
|
|
|
|
|
|
func TestTrek(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("live long and prosper"))
|
2019-01-19 16:06:13 +00:00
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
assert.True(t, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDune(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("bless the maker"))
|
2019-01-19 16:06:13 +00:00
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
assert.True(t, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPoke(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("gotta catch em all"))
|
2019-01-19 16:06:13 +00:00
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
assert.True(t, res)
|
|
|
|
}
|