2019-02-15 18:22:54 +00:00
|
|
|
|
package remember
|
2016-04-08 16:18:34 +00:00
|
|
|
|
|
|
|
|
|
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-15 18:22:54 +00:00
|
|
|
|
"github.com/velour/catbase/plugins/fact"
|
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) (*RememberPlugin, *fact.FactoidPlugin, *bot.MockBot) {
|
2016-04-08 16:18:34 +00:00
|
|
|
|
mb := bot.NewMockBot()
|
2019-02-15 18:22:54 +00:00
|
|
|
|
f := fact.New(mb) // for DB table
|
|
|
|
|
p := New(mb)
|
2016-04-08 16:18:34 +00:00
|
|
|
|
assert.NotNil(t, p)
|
|
|
|
|
return p, f, mb
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test case
|
|
|
|
|
func TestCornerCaseBug(t *testing.T) {
|
|
|
|
|
msgs := []msg.Message{
|
|
|
|
|
makeMessage("user1", "I don’t want to personally touch a horse dick."),
|
|
|
|
|
makeMessage("user3", "idk my bff rose?"),
|
|
|
|
|
makeMessage("user2", "!remember user1 touch"),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p, _, mb := makePlugin(t)
|
|
|
|
|
|
|
|
|
|
for _, m := range msgs {
|
2019-02-05 20:02:15 +00:00
|
|
|
|
p.message(bot.Message, m)
|
2016-04-08 16:18:34 +00:00
|
|
|
|
}
|
|
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
|
assert.Contains(t, mb.Messages[0], "horse dick")
|
2019-02-15 18:22:54 +00:00
|
|
|
|
q, err := fact.GetSingleFact(mb.DB(), "user1 quotes")
|
2016-04-08 16:18:34 +00:00
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.Contains(t, q.Tidbit, "horse dick")
|
|
|
|
|
}
|