catbase/plugins/picker/picker_test.go

47 lines
1.0 KiB
Go
Raw Normal View History

// © 2018 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
package picker
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) {
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"},
Channel: "test",
Body: payload,
Command: isCmd,
}
}
func TestPick2(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("!pick 2 { a, b,c}"))
assert.Len(t, mb.Messages, 1)
if !res {
t.Fatalf("expected a successful choice, got %q", mb.Messages[0])
}
}
func TestPickDefault(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
_ = c.message(makeMessage("!pick { a}"))
assert.Len(t, mb.Messages, 1)
assert.Equal(t, `I've chosen "a" for you.`, mb.Messages[0])
}