Exemplo n.º 1
0
func TestHandleChannels(t *testing.T) {
	assert := assert.New(t)
	c := &Core{}
	mb := core.NewMockBot(slack.UUIDv4().ToShortString())
	err := c.handleChannels(mb, core.MockMessage("channels"))
	assert.Nil(err)
}
Exemplo n.º 2
0
func TestHandleConfig(t *testing.T) {
	assert := assert.New(t)
	c := &Config{}
	mb := core.NewMockBot(slack.UUIDv4().ToShortString())
	mb.Configuration()["foo"] = "bar"

	handleErr := c.handleConfig(mb, core.MockMessage("config"))
	assert.Nil(handleErr)
}
Exemplo n.º 3
0
func TestHandleConfigSet(t *testing.T) {
	assert := assert.New(t)

	c := &Config{}
	mb := core.NewMockBot(slack.UUIDv4().ToShortString())
	handleErr := c.handleConfigSet(mb, core.MockMessage("config:foo bar"))
	assert.Nil(handleErr)
	assert.Equal("bar", mb.Configuration()["foo"])
}
Exemplo n.º 4
0
func TestHandleTell(t *testing.T) {
	assert := assert.New(t)
	c := &Core{}
	mb := core.NewMockBot(slack.UUIDv4().ToShortString())

	gotMessage := ""
	mb.MockMessageHandler(func(b core.Bot, m *slack.Message) error {
		gotMessage = m.Text
		return nil
	})

	err := c.handleTell(mb, core.MockMessage("tell <@TESTUSER> they're cool"))
	assert.Nil(err)
	assert.Equal("<@TESTUSER> you are cool", gotMessage)
}
Exemplo n.º 5
0
func TestHandleMentionCatchAllSalutation(t *testing.T) {
	assert := assert.New(t)
	c := &Core{}
	mb := core.NewMockBot(slack.UUIDv4().ToShortString())

	gotMessage := ""
	mb.MockMessageHandler(func(b core.Bot, m *slack.Message) error {
		gotMessage = m.Text
		return nil
	})

	message := "hey <@BOT>"
	assert.True(core.IsSalutation(message))
	err := c.handleSalutation(mb, core.MockMessage(message))
	assert.Nil(err)
	assert.False(strings.Contains(gotMessage, "how to respond"))
}
Exemplo n.º 6
0
func TestHandleConfigGet(t *testing.T) {
	assert := assert.New(t)
	c := &Config{}
	mb := core.NewMockBot(slack.UUIDv4().ToShortString())
	mb.Configuration()["foo"] = "bar"

	gotMessage := ""
	mb.MockMessageHandler(func(b core.Bot, m *slack.Message) error {
		gotMessage = m.Text
		return nil
	})

	handleErr := c.handleConfigGet(mb, core.MockMessage("config:foo"))
	assert.Nil(handleErr)
	assert.NotEmpty(gotMessage)
	assert.True(strings.Contains(gotMessage, "foo"))
	assert.True(strings.Contains(gotMessage, "bar"))
}