[MM-62179] Fix: mmctl debug error when setting email (#29953)

* only GetUserByEmail if arg is an email

* fixing tests

* fix typo
Этот коммит содержится в:
Christopher Poile
2025-01-29 17:45:11 -05:00
коммит произвёл GitHub
родитель 05ca61c784
Коммит 28c561d643
10 изменённых файлов: 31 добавлений и 378 удалений

Просмотреть файл

@@ -56,12 +56,6 @@ func (s *MmctlUnitTestSuite) TestBotCreateCmd() {
Return(&mockBot, &model.Response{}, nil).
Times(1)
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("no user found with the given email")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -116,12 +110,6 @@ func (s *MmctlUnitTestSuite) TestBotUpdateCmd() {
mockBot := model.Bot{Username: "new-username", DisplayName: "some-name", Description: "some-text"}
mockUser := model.User{Id: model.NewId()}
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -148,12 +136,6 @@ func (s *MmctlUnitTestSuite) TestBotUpdateCmd() {
cmd.Flags().String("username", "bot-username", "")
cmd.Flags().Lookup("username").Changed = true
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -183,12 +165,6 @@ func (s *MmctlUnitTestSuite) TestBotUpdateCmd() {
cmd.Flags().Lookup("description").Changed = true
mockUser := model.User{Id: model.NewId()}
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -417,12 +393,6 @@ func (s *MmctlUnitTestSuite) TestBotDisableCmd() {
mockBot := model.Bot{Username: botArg, DisplayName: "some-name", Description: "some-text"}
mockUser := model.User{Id: model.NewId()}
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -446,12 +416,6 @@ func (s *MmctlUnitTestSuite) TestBotDisableCmd() {
botArg := "a-bot"
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -481,12 +445,6 @@ func (s *MmctlUnitTestSuite) TestBotDisableCmd() {
cmd.Flags().Lookup("description").Changed = true
mockUser := model.User{Id: model.NewId()}
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -515,12 +473,6 @@ func (s *MmctlUnitTestSuite) TestBotEnableCmd() {
mockBot := model.Bot{Username: botArg, DisplayName: "some-name", Description: "some-text"}
mockUser := model.User{Id: model.NewId()}
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -544,12 +496,6 @@ func (s *MmctlUnitTestSuite) TestBotEnableCmd() {
botArg := "a-bot"
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -579,12 +525,6 @@ func (s *MmctlUnitTestSuite) TestBotEnableCmd() {
cmd.Flags().Lookup("description").Changed = true
mockUser := model.User{Id: model.NewId()}
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -615,24 +555,12 @@ func (s *MmctlUnitTestSuite) TestBotAssignCmd() {
mockBotUser := model.User{Id: model.NewId()}
mockNewOwner := model.User{Id: model.NewId()}
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
Return(&mockBotUser, &model.Response{}, nil).
Times(1)
s.client.
EXPECT().
GetUserByEmail(context.TODO(), userArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), userArg, "").
@@ -669,12 +597,6 @@ func (s *MmctlUnitTestSuite) TestBotAssignCmd() {
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
err := botAssignCmdF(s.client, &cobra.Command{}, []string{botArg, userArg})
s.Require().NotNil(err)
s.Require().Len(printer.GetLines(), 0)
@@ -689,12 +611,6 @@ func (s *MmctlUnitTestSuite) TestBotAssignCmd() {
mockBotUser := model.User{Id: model.NewId()}
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
@@ -713,12 +629,6 @@ func (s *MmctlUnitTestSuite) TestBotAssignCmd() {
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByEmail(context.TODO(), userArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
err := botAssignCmdF(s.client, &cobra.Command{}, []string{botArg, userArg})
s.Require().NotNil(err)
s.Require().Len(printer.GetLines(), 0)
@@ -734,24 +644,12 @@ func (s *MmctlUnitTestSuite) TestBotAssignCmd() {
mockBotUser := model.User{Id: model.NewId()}
mockNewOwner := model.User{Id: model.NewId()}
s.client.
EXPECT().
GetUserByEmail(context.TODO(), botArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), botArg, "").
Return(&mockBotUser, &model.Response{}, nil).
Times(1)
s.client.
EXPECT().
GetUserByEmail(context.TODO(), userArg, "").
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), userArg, "").