Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Add unit tests to the "DeleteTeamsCmd" mmctl command (#79)
Browse files Browse the repository at this point in the history
* Add unit tests to the "DeleteTeamsCmd" mmctl command

* make error message more meaninful
  • Loading branch information
0xVolodya authored and jespino committed Jan 7, 2020
1 parent 48ec4ab commit 9193f05
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions commands/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,3 +894,105 @@ func (s *MmctlUnitTestSuite) TestAddUsersCmd() {
s.Require().Len(printer.GetErrorLines(), 0)
})
}

func (s *MmctlUnitTestSuite) TestDeleteTeamsCmd() {
teamName := "team1"
teamId := "teamId"

s.Run("Delete teams with no arguments returns an error", func() {
cmd := &cobra.Command{}
err := deleteTeamsCmdF(s.client, cmd, []string{})
s.Require().NotNil(err)
s.Require().Equal(err.Error(), "Not enough arguments.")
})

s.Run("Delete teams with confirm false returns an error", func() {
cmd := &cobra.Command{}
cmd.Flags().Bool("confirm", false, "")
err := deleteTeamsCmdF(s.client, cmd, []string{"some"})
s.Require().NotNil(err)
s.Require().Equal(err.Error(), "ABORTED: You did not answer YES exactly, in all capitals.")
})

s.Run("Delete teams with team not exist in db returns an error", func() {
printer.Clean()

s.client.
EXPECT().
GetTeamByName(teamName, "").
Return(nil, &model.Response{Error: nil}).
Times(1)

s.client.
EXPECT().
GetTeam(teamName, "").
Return(nil, &model.Response{Error: nil}).
Times(1)

cmd := &cobra.Command{}
cmd.Flags().Bool("confirm", true, "")

err := deleteTeamsCmdF(s.client, cmd, []string{"team1"})
s.Require().Nil(err)
s.Require().Equal("Unable to find team 'team1'", printer.GetErrorLines()[0])
})

s.Run("Delete teams should delete team", func() {
printer.Clean()
mockTeam := model.Team{
Id: teamId,
Name: teamName,
}

s.client.
EXPECT().
PermanentDeleteTeam(teamId).
Return(true, &model.Response{Error: nil}).
Times(1)
s.client.
EXPECT().
GetTeam(teamName, "").
Return(&mockTeam, &model.Response{Error: nil}).
Times(1)

cmd := &cobra.Command{}
cmd.Flags().Bool("confirm", true, "")

err := deleteTeamsCmdF(s.client, cmd, []string{"team1"})
s.Require().Nil(err)
s.Require().Equal(&mockTeam, printer.GetLines()[0])
})

s.Run("Delete teams with error on PermanentDeleteTeam returns an error", func() {
printer.Clean()
mockTeam := model.Team{
Id: teamId,
Name: teamName,
}

mockError := &model.AppError{
Message: "An error occurred on deleting a team",
DetailedError: "Team cannot be deleted",
Where: "Team.deleteTeam",
}
s.client.
EXPECT().
PermanentDeleteTeam(teamId).
Return(false, &model.Response{Error: mockError}).
Times(1)

s.client.
EXPECT().
GetTeam(teamName, "").
Return(&mockTeam, &model.Response{Error: nil}).
Times(1)

cmd := &cobra.Command{}
cmd.Flags().Bool("confirm", true, "")

err := deleteTeamsCmdF(s.client, cmd, []string{"team1"})
s.Require().Nil(err)
s.Require().Equal("Unable to delete team 'team1' error: Team.deleteTeam: An error occurred on deleting a team, Team cannot be deleted",
printer.GetErrorLines()[0])
})
}

0 comments on commit 9193f05

Please sign in to comment.