From f6e0310b502f5075659eb5a830d88e2026ee5f50 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Thu, 24 Aug 2017 00:19:15 +0800 Subject: [PATCH] [PLT-7390] Add Type = 'O' in getting open teams at sql store (#7207) * add Type = 'O' in getting open teams at sql store * updated PR --- api4/team_test.go | 16 +++-- store/sql_team_store_test.go | 115 ++++++++++++++++++++++++++++++++++- 2 files changed, 126 insertions(+), 5 deletions(-) diff --git a/api4/team_test.go b/api4/team_test.go index 21c842f6571..1f977211344 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -423,12 +423,20 @@ func TestGetAllTeams(t *testing.T) { t.Fatal("wrong number of teams - should be 1") } - // temporarily disable this test - /*for _, rt := range rrteams { - if rt.Type != model.TEAM_OPEN { + for _, rt := range rrteams { + if !rt.AllowOpenInvite { t.Fatal("not all teams are open") } - }*/ + } + + rrteams, resp = Client.GetAllTeams("", 0, 10) + CheckNoError(t, resp) + + for _, rt := range rrteams { + if !rt.AllowOpenInvite { + t.Fatal("not all teams are open") + } + } rrteams1, resp := Client.GetAllTeams("", 1, 0) CheckNoError(t, resp) diff --git a/store/sql_team_store_test.go b/store/sql_team_store_test.go index e3e6413f17a..da45e4eae03 100644 --- a/store/sql_team_store_test.go +++ b/store/sql_team_store_test.go @@ -379,7 +379,7 @@ func TestTeamStoreByUserId(t *testing.T) { } } -func TestAllTeamListing(t *testing.T) { +func TestGetAllTeamListing(t *testing.T) { Setup() o1 := model.Team{} @@ -397,17 +397,130 @@ func TestAllTeamListing(t *testing.T) { o2.Type = model.TEAM_OPEN Must(store.Team().Save(&o2)) + o3 := model.Team{} + o3.DisplayName = "DisplayName" + o3.Name = "z-z-z" + model.NewId() + "b" + o3.Email = model.NewId() + "@nowhere.com" + o3.Type = model.TEAM_INVITE + o3.AllowOpenInvite = true + Must(store.Team().Save(&o3)) + + o4 := model.Team{} + o4.DisplayName = "DisplayName" + o4.Name = "zz" + model.NewId() + "b" + o4.Email = model.NewId() + "@nowhere.com" + o4.Type = model.TEAM_INVITE + Must(store.Team().Save(&o4)) + if r1 := <-store.Team().GetAllTeamListing(); r1.Err != nil { t.Fatal(r1.Err) } else { teams := r1.Data.([]*model.Team) + for _, team := range teams { + if !team.AllowOpenInvite { + t.Fatal("should have returned team with AllowOpenInvite as true") + } + } + if len(teams) == 0 { t.Fatal("failed team listing") } } } +func TestGetAllTeamPageListing(t *testing.T) { + Setup() + + o1 := model.Team{} + o1.DisplayName = "DisplayName" + o1.Name = "z-z-z" + model.NewId() + "b" + o1.Email = model.NewId() + "@nowhere.com" + o1.Type = model.TEAM_OPEN + o1.AllowOpenInvite = true + Must(store.Team().Save(&o1)) + + o2 := model.Team{} + o2.DisplayName = "DisplayName" + o2.Name = "zz" + model.NewId() + "b" + o2.Email = model.NewId() + "@nowhere.com" + o2.Type = model.TEAM_OPEN + o2.AllowOpenInvite = false + Must(store.Team().Save(&o2)) + + o3 := model.Team{} + o3.DisplayName = "DisplayName" + o3.Name = "z-z-z" + model.NewId() + "b" + o3.Email = model.NewId() + "@nowhere.com" + o3.Type = model.TEAM_INVITE + o3.AllowOpenInvite = true + Must(store.Team().Save(&o3)) + + o4 := model.Team{} + o4.DisplayName = "DisplayName" + o4.Name = "zz" + model.NewId() + "b" + o4.Email = model.NewId() + "@nowhere.com" + o4.Type = model.TEAM_INVITE + o4.AllowOpenInvite = false + Must(store.Team().Save(&o4)) + + if r1 := <-store.Team().GetAllTeamPageListing(0, 10); r1.Err != nil { + t.Fatal(r1.Err) + } else { + teams := r1.Data.([]*model.Team) + + for _, team := range teams { + if !team.AllowOpenInvite { + t.Fatal("should have returned team with AllowOpenInvite as true") + } + } + + if len(teams) > 10 { + t.Fatal("should have returned max of 10 teams") + } + } + + o5 := model.Team{} + o5.DisplayName = "DisplayName" + o5.Name = "z-z-z" + model.NewId() + "b" + o5.Email = model.NewId() + "@nowhere.com" + o5.Type = model.TEAM_OPEN + o5.AllowOpenInvite = true + Must(store.Team().Save(&o5)) + + if r1 := <-store.Team().GetAllTeamPageListing(0, 4); r1.Err != nil { + t.Fatal(r1.Err) + } else { + teams := r1.Data.([]*model.Team) + + for _, team := range teams { + if !team.AllowOpenInvite { + t.Fatal("should have returned team with AllowOpenInvite as true") + } + } + + if len(teams) > 4 { + t.Fatal("should have returned max of 4 teams") + } + } + + if r1 := <-store.Team().GetAllTeamPageListing(1, 1); r1.Err != nil { + t.Fatal(r1.Err) + } else { + teams := r1.Data.([]*model.Team) + + for _, team := range teams { + if !team.AllowOpenInvite { + t.Fatal("should have returned team with AllowOpenInvite as true") + } + } + + if len(teams) > 1 { + t.Fatal("should have returned max of 1 team") + } + } +} + func TestDelete(t *testing.T) { Setup()