catbase/plugins/rss/rss_test.go

59 lines
1.3 KiB
Go
Raw Permalink Normal View History

2017-05-10 19:15:24 +00:00
package rss
import (
2017-05-10 19:56:03 +00:00
"fmt"
2017-05-10 19:15:24 +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
func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) {
2017-05-10 19:15:24 +00:00
isCmd := strings.HasPrefix(payload, "!")
if isCmd {
payload = payload[1:]
}
return nil, bot.Message, msg.Message{
2017-05-10 19:15:24 +00:00
User: &user.User{Name: "tester"},
Channel: "test",
Body: payload,
Command: isCmd,
}
}
func TestRSS(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("!rss http://rss.cnn.com/rss/edition.rss"))
2017-05-10 19:15:24 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
}
2017-05-10 19:56:03 +00:00
func TestRSSPaging(t *testing.T) {
2017-05-10 19:15:24 +00:00
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2017-05-10 19:56:03 +00:00
for i := 0; i < 20; i++ {
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!rss http://rss.cnn.com/rss/edition.rss"))
2017-05-10 19:56:03 +00:00
assert.True(t, res)
}
assert.Len(t, mb.Messages, 20)
for i := 0; i < len(mb.Messages); i++ {
if i > 0 && strings.Contains(mb.Messages[i], "CNN.com - RSS Channel - Intl Homepage - News") {
fmt.Println("----------------")
fmt.Println(mb.Messages[i])
fmt.Println("----------------")
break
}
fmt.Println("----------------")
fmt.Println(mb.Messages[i])
fmt.Println("----------------")
}
2017-05-10 19:15:24 +00:00
}