summaryrefslogtreecommitdiffstats
path: root/api/team_test.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2016-12-08 16:21:43 +0100
committerHarrison Healey <harrisonmhealey@gmail.com>2016-12-08 10:21:43 -0500
commitd402b1d010a56256f15bb482684c18b10ed4bcc5 (patch)
tree0f94813e07ced23c05b22dd302048698e88a7466 /api/team_test.go
parentb57c9fec89f736de8622218d6dc779012a266a91 (diff)
downloadchat-d402b1d010a56256f15bb482684c18b10ed4bcc5.tar.gz
chat-d402b1d010a56256f15bb482684c18b10ed4bcc5.tar.bz2
chat-d402b1d010a56256f15bb482684c18b10ed4bcc5.zip
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
Diffstat (limited to 'api/team_test.go')
-rw-r--r--api/team_test.go69
1 files changed, 69 insertions, 0 deletions
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")
+ }
+
+}