From 86d027430632105ebd3d0b7157a06dbb159d020e Mon Sep 17 00:00:00 2001 From: Mateusz Szostok Date: Mon, 13 Feb 2023 14:48:24 +0100 Subject: [PATCH] Add unit test, fix actions --- pkg/action/provider.go | 3 +- pkg/bot/socketslack_test.go | 77 +++++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/pkg/action/provider.go b/pkg/action/provider.go index eb587da1c1..d1f25fd96b 100644 --- a/pkg/action/provider.go +++ b/pkg/action/provider.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "html/template" + "strings" sprig "github.com/go-task/slim-sprig" "github.com/sirupsen/logrus" @@ -90,7 +91,7 @@ func (p *Provider) ExecuteEventAction(ctx context.Context, action event.Action) CommGroupName: unknownValue, Platform: unknownValue, NotifierHandler: &universalNotifierHandler{}, - Message: action.Command, + Message: strings.TrimSpace(strings.TrimPrefix(action.Command, api.MessageBotNamePlaceholder)), User: fmt.Sprintf("Automation %q", action.DisplayName), }) response := e.Execute(ctx) diff --git a/pkg/bot/socketslack_test.go b/pkg/bot/socketslack_test.go index f6f6d8ec86..48396ff15b 100644 --- a/pkg/bot/socketslack_test.go +++ b/pkg/bot/socketslack_test.go @@ -2,33 +2,60 @@ package bot import ( "testing" + + "github.com/slack-go/slack" + "github.com/stretchr/testify/assert" ) func TestNormalizeState(t *testing.T) { - //// given - //fix := []*slack.BlockAction{ - // { - // ActionID: "@Botkube kubectl @builder --verbs", - // BlockID: "13a13f04-4fc8-47e1-a167-f87980b3e834", - // Type: "static_select", - // ActionTs: "1675869299.369379", - // SelectedOption: slack.OptionBlockObject{ - // Text: &slack.TextBlockObject{ - // Type: "plain_text", - // Text: "get", - // Emoji: true, - // }, - // Value: "get", - // }, - // }, - //} - //fx := &slack.BlockActionStates{ - // Values: map[string]map[string]slack.BlockAction{ - // "" - // }, - //} - //// when - //out := removeBotNameFromIDs("@Botkube", fix) - //// then + // given + fix := &slack.BlockActionStates{ + Values: map[string]map[string]slack.BlockAction{ + "dropdown-block-id-403aca17d958": { + "@Botkube kc-cmd-builder --resource-name": { + SelectedOption: slack.OptionBlockObject{ + Value: "nginx2", + }, + }, + "@Botkube kc-cmd-builder --resource-type": slack.BlockAction{ + SelectedOption: slack.OptionBlockObject{ + Value: "pods", + }, + }, + "@Botkube kc-cmd-builder --verbs": slack.BlockAction{ + SelectedOption: slack.OptionBlockObject{ + Value: "get", + }, + }, + }, + }, + } + + exp := &slack.BlockActionStates{ + Values: map[string]map[string]slack.BlockAction{ + "dropdown-block-id-403aca17d958": { + "kc-cmd-builder --resource-name": { + SelectedOption: slack.OptionBlockObject{ + Value: "nginx2", + }, + }, + "kc-cmd-builder --resource-type": slack.BlockAction{ + SelectedOption: slack.OptionBlockObject{ + Value: "pods", + }, + }, + "kc-cmd-builder --verbs": slack.BlockAction{ + SelectedOption: slack.OptionBlockObject{ + Value: "get", + }, + }, + }, + }, + } + + // when + out := removeBotNameFromIDs("@Botkube", fix) + // then + assert.Equal(t, exp, out) }