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