2016-03-30 23:04:49 +00:00
|
|
|
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
|
|
|
|
|
|
|
package dice
|
|
|
|
|
|
|
|
import (
|
2019-05-27 23:21:53 +00:00
|
|
|
"github.com/velour/catbase/plugins/cli"
|
2016-03-30 23:04:49 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/velour/catbase/bot"
|
2016-04-01 14:20:03 +00:00
|
|
|
"github.com/velour/catbase/bot/msg"
|
|
|
|
"github.com/velour/catbase/bot/user"
|
2016-03-30 23:04:49 +00:00
|
|
|
)
|
|
|
|
|
2019-05-27 23:21:53 +00:00
|
|
|
func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) {
|
2016-03-30 23:04:49 +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-04-01 14:20:03 +00:00
|
|
|
User: &user.User{Name: "tester"},
|
2016-03-30 23:04:49 +00:00
|
|
|
Channel: "test",
|
|
|
|
Body: payload,
|
|
|
|
Command: isCmd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDie(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("!1d6"))
|
2016-03-30 23:04:49 +00:00
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
assert.True(t, res)
|
|
|
|
assert.Contains(t, mb.Messages[0], "tester, you rolled:")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDice(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("!5d6"))
|
2016-03-30 23:04:49 +00:00
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
assert.True(t, res)
|
|
|
|
assert.Contains(t, mb.Messages[0], "tester, you rolled:")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotCommand(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("1d6"))
|
2016-03-30 23:04:49 +00:00
|
|
|
assert.False(t, res)
|
|
|
|
assert.Len(t, mb.Messages, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBadDice(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("!aued6"))
|
2016-03-30 23:04:49 +00:00
|
|
|
assert.False(t, res)
|
|
|
|
assert.Len(t, mb.Messages, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBadSides(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("!1daoeu"))
|
2016-03-30 23:04:49 +00:00
|
|
|
assert.False(t, res)
|
|
|
|
assert.Len(t, mb.Messages, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLotsOfDice(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("!100d100"))
|
2016-03-30 23:04:49 +00:00
|
|
|
assert.True(t, res)
|
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
assert.Contains(t, mb.Messages[0], "You're a dick.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHelp(t *testing.T) {
|
|
|
|
mb := bot.NewMockBot()
|
|
|
|
c := New(mb)
|
|
|
|
assert.NotNil(t, c)
|
2019-05-27 23:21:53 +00:00
|
|
|
c.help(&cli.CliPlugin{}, bot.Help, msg.Message{Channel: "channel"}, []string{})
|
2016-03-30 23:04:49 +00:00
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
}
|