Skip to content

Commit

Permalink
[PLT-7390] Add Type = 'O' in getting open teams at sql store (matterm…
Browse files Browse the repository at this point in the history
…ost#7207)

* add Type = 'O' in getting open teams at sql store

* updated PR
  • Loading branch information
saturninoabril authored Aug 23, 2017
1 parent 7dad396 commit f6e0310
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 5 deletions.
16 changes: 12 additions & 4 deletions api4/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
115 changes: 114 additions & 1 deletion store/sql_team_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func TestTeamStoreByUserId(t *testing.T) {
}
}

func TestAllTeamListing(t *testing.T) {
func TestGetAllTeamListing(t *testing.T) {
Setup()

o1 := model.Team{}
Expand All @@ -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()

Expand Down

0 comments on commit f6e0310

Please sign in to comment.