Example #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)
}
Example #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)
}
Example #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"])
}
Example #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)
}
Example #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"))
}
Example #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"))
}