Skip to content

Commit

Permalink
Add unit test, fix actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Feb 13, 2023
1 parent e13cd56 commit 86d0274
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
3 changes: 2 additions & 1 deletion pkg/action/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"html/template"
"strings"

sprig "github.com/go-task/slim-sprig"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -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)
Expand Down
77 changes: 52 additions & 25 deletions pkg/bot/socketslack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 86d0274

Please sign in to comment.