From d402b1d010a56256f15bb482684c18b10ed4bcc5 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Thu, 8 Dec 2016 16:21:43 +0100 Subject: Add API call to get a team by its name (#4690) * Add API call to get a team by its name * add tests for client side and update route regex * remove action * add check for permissions and create tests --- api/team_test.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'api/team_test.go') diff --git a/api/team_test.go b/api/team_test.go index bb7d19e4f..5880ffcff 100644 --- a/api/team_test.go +++ b/api/team_test.go @@ -797,3 +797,72 @@ func TestUpdateTeamDescription(t *testing.T) { t.Fatal(err) } } + +func TestGetTeamByName(t *testing.T) { + th := Setup().InitSystemAdmin().InitBasic() + th.BasicClient.Logout() + Client := th.BasicClient + + team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_INVITE} + team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) + + team2 := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN} + team2 = Client.Must(Client.CreateTeam(team2)).Data.(*model.Team) + + user := &model.User{Email: team.Email, Nickname: "My Testing", Password: "passwd1"} + user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) + LinkUserToTeam(user, team) + store.Must(Srv.Store.User().VerifyEmail(user.Id)) + + Client.Login(user.Email, "passwd1") + if _, err := Client.GetTeamByName(team.Name); err != nil { + t.Fatal("Failed to get team") + } + + if _, err := Client.GetTeamByName("InvalidTeamName"); err == nil { + t.Fatal("Should not exist this team") + } + + if _, err := Client.GetTeamByName(team2.Name); err != nil { + t.Fatal("Failed to get team") + } + + Client.Must(Client.Logout()) + + user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Jabba the Hutt", Password: "passwd1"} + user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) + store.Must(Srv.Store.User().VerifyEmail(user2.Id)) + + Client.Login(user2.Email, "passwd1") + + // TEAM_INVITE and user is not part of the team + if _, err := Client.GetTeamByName(team.Name); err == nil { + t.Fatal("Should not fail dont have permissions to get the team") + } + + if _, err := Client.GetTeamByName("InvalidTeamName"); err == nil { + t.Fatal("Should not exist this team") + } + + // TEAM_OPEN and user is not part of the team + if _, err := Client.GetTeamByName(team2.Name); err != nil { + t.Fatal("Should not fail team is open") + } + + Client.Must(Client.Logout()) + th.BasicClient.Logout() + th.LoginSystemAdmin() + + if _, err := th.SystemAdminClient.GetTeamByName(team.Name); err != nil { + t.Fatal("Should not failed to get team the user is admin") + } + + if _, err := th.SystemAdminClient.GetTeamByName(team2.Name); err != nil { + t.Fatal("Should not failed to get team the user is admin and team is open") + } + + if _, err := Client.GetTeamByName("InvalidTeamName"); err == nil { + t.Fatal("Should not exist this team") + } + +} -- cgit v1.2.3-1-g7c22