[GH-21216] Function removeUserFromChannel return error (#26428)

Этот коммит содержится в:
Anna Os
2024-03-25 12:53:22 +01:00
коммит произвёл GitHub
родитель ba2d11ff3d
Коммит 00d48b04ed
4 изменённых файлов: 97 добавлений и 30 удалений

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

@@ -159,10 +159,10 @@ func (s *MmctlUnitTestSuite) TestChannelUsersAddCmdF() {
Return(&model.ChannelMember{}, &model.Response{}, nil).
Times(1)
err := channelUsersAddCmdF(s.client, cmd, []string{channelArg, nilUserArg, userEmail})
s.Require().Nil(err)
s.Require().ErrorContains(err, "unable to find user")
s.Require().ErrorContains(err, nilUserArg)
s.Len(printer.GetLines(), 0)
s.Len(printer.GetErrorLines(), 1)
s.Equal("Can't find user '"+nilUserArg+"'", printer.GetErrorLines()[0])
})
s.Run("Error adding existing user to existing channel", func() {
printer.Clean()
@@ -191,11 +191,11 @@ func (s *MmctlUnitTestSuite) TestChannelUsersAddCmdF() {
Return(nil, &model.Response{}, errors.New("mock error")).
Times(1)
err := channelUsersAddCmdF(s.client, cmd, []string{channelArg, userEmail})
s.Require().Nil(err)
s.Require().ErrorContains(err, "unable to add")
s.Require().ErrorContains(err, userEmail)
s.Require().ErrorContains(err, channelName)
s.Len(printer.GetLines(), 0)
s.Len(printer.GetErrorLines(), 1)
s.Equal("Unable to add '"+userEmail+"' to "+channelName+". Error: mock error",
printer.GetErrorLines()[0])
})
}
@@ -439,4 +439,54 @@ func (s *MmctlUnitTestSuite) TestChannelUsersRemoveCmd() {
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
})
s.Run("should remove user from channel throws error", func() {
printer.Clean()
cmd := &cobra.Command{}
args := []string{argsTeamChannel, userEmail}
foundTeam := &model.Team{
Id: teamID,
DisplayName: teamDisplayName,
Name: teamName,
}
foundChannel := &model.Channel{
Id: channelID,
Name: channelName,
DisplayName: channelDisplayName,
}
s.client.
EXPECT().
GetTeam(context.TODO(), teamName, "").
Return(foundTeam, &model.Response{}, nil).
Times(1)
s.client.
EXPECT().
GetChannelByNameIncludeDeleted(context.TODO(), channelName, foundTeam.Id, "").
Return(foundChannel, &model.Response{}, nil).
Times(1)
s.client.
EXPECT().
GetUserByEmail(context.TODO(), userEmail, "").
Return(&mockUser, &model.Response{}, nil).
Times(1)
s.client.
EXPECT().
RemoveUserFromChannel(context.TODO(), foundChannel.Id, mockUser.Id).
Return(&model.Response{StatusCode: http.StatusNotFound}, errors.New("mock error")).
Times(1)
err := channelUsersRemoveCmdF(s.client, cmd, args)
s.Require().ErrorContains(err, "unable to remove")
s.Require().ErrorContains(err, userEmail)
s.Require().ErrorContains(err, channelName)
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
})
}