diff --git a/server/cmd/mmctl/commands/command_e2e_test.go b/server/cmd/mmctl/commands/command_e2e_test.go index 73d61e2a06..8a9508f83f 100644 --- a/server/cmd/mmctl/commands/command_e2e_test.go +++ b/server/cmd/mmctl/commands/command_e2e_test.go @@ -318,3 +318,61 @@ func (s *MmctlE2ETestSuite) TestModifyCommandCmdF() { s.EqualError(err, "a trigger word must not contain spaces") }) } + +func (s *MmctlE2ETestSuite) TestShowCommandCmdF() { + s.SetupTestHelper().InitBasic() + + s.RunForSystemAdminAndLocal("Show non existent cmd", func(c client.Client) { + printer.Clean() + + err := showCommandCmdF(c, &cobra.Command{}, []string{"nonexistent-command-id"}) + s.Require().Error(err) + s.Require().Equal("unable to find command 'nonexistent-command-id'", err.Error()) + s.Require().Len(printer.GetLines(), 0) + s.Require().Len(printer.GetErrorLines(), 0) + }) + + s.RunForSystemAdminAndLocal("Show commands with cmd id", func(c client.Client) { + // create new command + printer.Clean() + newCmd := &model.Command{ + CreatorId: s.th.BasicUser.Id, + TeamId: s.th.BasicTeam.Id, + URL: "http://nowhere.com", + Method: model.CommandMethodPost, + Trigger: model.NewRandomString(6), + } + + command, _, err := c.CreateCommand(context.Background(), newCmd) + s.Require().NoError(err) + err = showCommandCmdF(c, &cobra.Command{}, []string{command.Id}) + s.Require().NoError(err) + s.Len(printer.GetLines(), 1) + s.Len(printer.GetErrorLines(), 0) + s.Equal(command, printer.GetLines()[0]) + }) + + s.RunForSystemAdminAndLocal("Show commands with team:trigger", func(c client.Client) { + // create new command + printer.Clean() + trigger := model.NewRandomString(6) + newCmd := &model.Command{ + CreatorId: s.th.BasicUser.Id, + TeamId: s.th.BasicTeam.Id, + URL: "http://nowhere.com", + Method: model.CommandMethodPost, + Trigger: trigger, + } + + command, _, err := c.CreateCommand(context.Background(), newCmd) + + s.Require().NoError(err) + err = showCommandCmdF(c, &cobra.Command{}, []string{s.th.BasicTeam.Name + ":" + trigger}) + s.Require().NoError(err) + s.Len(printer.GetLines(), 1) + s.Len(printer.GetErrorLines(), 0) + outputCmd := printer.GetLines()[0].(*model.Command) + s.Require().Equal(command.TeamId, outputCmd.TeamId) + s.Require().Equal(command.Trigger, outputCmd.Trigger) + }) +}