-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add origin extraction for cmd execution, add user display name for in…
…teractive command (#1330) The changes introduce a feature that allows explicit origin extraction for the execution of commands. Furthermore, for commands that do not have an explicit origin, a fallback strategy has been implemented to determine the command origin based on activity type.
- Loading branch information
Showing
7 changed files
with
139 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package bot | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/infracloudio/msbotbuilder-go/schema" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/kubeshop/botkube/pkg/execute/command" | ||
) | ||
|
||
func TestExtractExplicitOrigin(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
givenAct schema.Activity | ||
wantOrigin command.Origin | ||
}{ | ||
{ | ||
name: "Should return explicit origin", | ||
givenAct: schema.Activity{ | ||
Type: schema.Message, | ||
Value: explicitOriginValue(string(command.MultiSelectValueChangeOrigin)), | ||
}, | ||
wantOrigin: command.MultiSelectValueChangeOrigin, | ||
}, | ||
{ | ||
name: "Should return typed message resolved from type due to invalid value", | ||
givenAct: schema.Activity{ | ||
Type: schema.Message, | ||
Value: explicitOriginValue("malformed-or-unknown-origin"), | ||
}, | ||
wantOrigin: command.TypedOrigin, | ||
}, | ||
{ | ||
name: "Should return btn click origin resolved from type because value is nil", | ||
givenAct: schema.Activity{ | ||
Type: schema.Invoke, | ||
Value: nil, | ||
}, | ||
wantOrigin: command.ButtonClickOrigin, | ||
}, | ||
{ | ||
name: "Should return unknown origin because value does not contain origin key and type is empty", | ||
givenAct: schema.Activity{Value: map[string]any{}}, | ||
wantOrigin: command.UnknownOrigin, | ||
}, | ||
} | ||
|
||
cloudTeam := &CloudTeams{} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
gotOrigin := cloudTeam.mapToCommandOrigin(tc.givenAct) | ||
assert.Equal(t, tc.wantOrigin, gotOrigin) | ||
}) | ||
} | ||
} | ||
|
||
func explicitOriginValue(in string) map[string]any { | ||
return map[string]any{ | ||
originKeyName: in, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters