[MM-18119] Add methods for getting teams and count when query… (#12020)

* Add methods to handle include_total_count api parameter when permissions
for authenticated user is not sysadmin

* Add translations for app errors

* Add Mocks

* Add tests for new methods

* When running at the TeamStore testing level, the number of returned
teams is different than running tests individually.  Fix for now and
submit help wanted do proper teardown after each test

* correct value when running test at the top level

* Add helper function to delete previous teams in db

* Instead of checking against numbers of teams returned, check against the
actual teams returned.
When creating test teams, use unique DisplaName values so the return
array will be sorted consistantly.
When testing private and public team counts, add teams that should not
be counted.  Also create odd number of public/private teams for better
error protections.  Don't want 1 of each type
This commit is contained in:
jfrerich
2019-09-10 11:50:27 -05:00
committed by GitHub
parent 9e6c5e8ea6
commit 1802c575e5
42 changed files with 483 additions and 85 deletions

View File

@@ -381,6 +381,21 @@ func (s SqlTeamStore) GetAllPrivateTeamListing() ([]*model.Team, *model.AppError
return data, nil
}
func (s SqlTeamStore) GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {
query := "SELECT * FROM Teams WHERE AllowOpenInvite = 1 ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
query = "SELECT * FROM Teams WHERE AllowOpenInvite = true ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
}
var data []*model.Team
if _, err := s.GetReplica().Select(&data, query, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
return nil, model.NewAppError("SqlTeamStore.GetAllPrivateTeamListing", "store.sql_team.get_all_private_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return data, nil
}
func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {
query := "SELECT * FROM Teams WHERE AllowOpenInvite = 0 ORDER BY DisplayName LIMIT :Limit OFFSET :Offset"
@@ -433,6 +448,35 @@ func (s SqlTeamStore) PermanentDelete(teamId string) *model.AppError {
return nil
}
func (s SqlTeamStore) AnalyticsPublicTeamCount() (int64, *model.AppError) {
c, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0 AND AllowOpenInvite = 1", map[string]interface{}{})
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
c, err = s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0 AND AllowOpenInvite = true", map[string]interface{}{})
}
if err != nil {
return int64(0), model.NewAppError("SqlTeamStore.AnalyticsPublicTeamCount", "store.sql_team.analytics_public_team_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return c, nil
}
func (s SqlTeamStore) AnalyticsPrivateTeamCount() (int64, *model.AppError) {
c, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0 AND AllowOpenInvite = 0", map[string]interface{}{})
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
c, err = s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0 AND AllowOpenInvite = false", map[string]interface{}{})
}
if err != nil {
return int64(0), model.NewAppError("SqlTeamStore.AnalyticsPrivateTeamCount", "store.sql_team.analytics_private_team_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return c, nil
}
func (s SqlTeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
c, err := s.GetReplica().SelectInt("SELECT COUNT(*) FROM Teams WHERE DeleteAt = 0", map[string]interface{}{})

View File

@@ -70,12 +70,15 @@ type TeamStore interface {
GetAllPage(offset int, limit int) ([]*model.Team, *model.AppError)
GetAllPrivateTeamListing() ([]*model.Team, *model.AppError)
GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
GetAllTeamListing() ([]*model.Team, *model.AppError)
GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
GetTeamsByUserId(userId string) ([]*model.Team, *model.AppError)
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
PermanentDelete(teamId string) *model.AppError
AnalyticsTeamCount() (int64, *model.AppError)
AnalyticsPublicTeamCount() (int64, *model.AppError)
AnalyticsPrivateTeamCount() (int64, *model.AppError)
SaveMember(member *model.TeamMember, maxUsersPerTeam int) (*model.TeamMember, *model.AppError)
UpdateMember(member *model.TeamMember) (*model.TeamMember, *model.AppError)
GetMember(teamId string, userId string) (*model.TeamMember, *model.AppError)

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// AuditStore is an autogenerated mock type for the AuditStore type
type AuditStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// BotStore is an autogenerated mock type for the BotStore type
type BotStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// ChannelMemberHistoryStore is an autogenerated mock type for the ChannelMemberHistoryStore type
type ChannelMemberHistoryStore struct {

View File

@@ -4,9 +4,11 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import store "github.com/mattermost/mattermost-server/store"
import (
model "github.com/mattermost/mattermost-server/model"
store "github.com/mattermost/mattermost-server/store"
mock "github.com/stretchr/testify/mock"
)
// ChannelStore is an autogenerated mock type for the ChannelStore type
type ChannelStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// ClusterDiscoveryStore is an autogenerated mock type for the ClusterDiscoveryStore type
type ClusterDiscoveryStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// CommandStore is an autogenerated mock type for the CommandStore type
type CommandStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// CommandWebhookStore is an autogenerated mock type for the CommandWebhookStore type
type CommandWebhookStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// ComplianceStore is an autogenerated mock type for the ComplianceStore type
type ComplianceStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// EmojiStore is an autogenerated mock type for the EmojiStore type
type EmojiStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// FileInfoStore is an autogenerated mock type for the FileInfoStore type
type FileInfoStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// GroupStore is an autogenerated mock type for the GroupStore type
type GroupStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// JobStore is an autogenerated mock type for the JobStore type
type JobStore struct {

View File

@@ -4,10 +4,14 @@
package mocks
import context "context"
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import store "github.com/mattermost/mattermost-server/store"
import (
context "context"
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
store "github.com/mattermost/mattermost-server/store"
)
// LayeredStoreDatabaseLayer is an autogenerated mock type for the LayeredStoreDatabaseLayer type
type LayeredStoreDatabaseLayer struct {

View File

@@ -4,10 +4,14 @@
package mocks
import context "context"
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import store "github.com/mattermost/mattermost-server/store"
import (
context "context"
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
store "github.com/mattermost/mattermost-server/store"
)
// LayeredStoreSupplier is an autogenerated mock type for the LayeredStoreSupplier type
type LayeredStoreSupplier struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// LicenseStore is an autogenerated mock type for the LicenseStore type
type LicenseStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// LinkMetadataStore is an autogenerated mock type for the LinkMetadataStore type
type LinkMetadataStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// OAuthStore is an autogenerated mock type for the OAuthStore type
type OAuthStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// PluginStore is an autogenerated mock type for the PluginStore type
type PluginStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// PostStore is an autogenerated mock type for the PostStore type
type PostStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// PreferenceStore is an autogenerated mock type for the PreferenceStore type
type PreferenceStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// ReactionStore is an autogenerated mock type for the ReactionStore type
type ReactionStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// RoleStore is an autogenerated mock type for the RoleStore type
type RoleStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// SchemeStore is an autogenerated mock type for the SchemeStore type
type SchemeStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// SessionStore is an autogenerated mock type for the SessionStore type
type SessionStore struct {

View File

@@ -4,11 +4,14 @@
package mocks
import gorp "github.com/mattermost/gorp"
import mock "github.com/stretchr/testify/mock"
import (
gorp "github.com/mattermost/gorp"
mock "github.com/stretchr/testify/mock"
import squirrel "github.com/Masterminds/squirrel"
import store "github.com/mattermost/mattermost-server/store"
squirrel "github.com/Masterminds/squirrel"
store "github.com/mattermost/mattermost-server/store"
)
// SqlStore is an autogenerated mock type for the SqlStore type
type SqlStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// StatusStore is an autogenerated mock type for the StatusStore type
type StatusStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import store "github.com/mattermost/mattermost-server/store"
import (
store "github.com/mattermost/mattermost-server/store"
mock "github.com/stretchr/testify/mock"
)
// Store is an autogenerated mock type for the Store type
type Store struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// SystemStore is an autogenerated mock type for the SystemStore type
type SystemStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// TeamStore is an autogenerated mock type for the TeamStore type
type TeamStore struct {
@@ -35,6 +37,52 @@ func (_m *TeamStore) AnalyticsGetTeamCountForScheme(schemeId string) (int64, *mo
return r0, r1
}
// AnalyticsPrivateTeamCount provides a mock function with given fields:
func (_m *TeamStore) AnalyticsPrivateTeamCount() (int64, *model.AppError) {
ret := _m.Called()
var r0 int64
if rf, ok := ret.Get(0).(func() int64); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int64)
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func() *model.AppError); ok {
r1 = rf()
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// AnalyticsPublicTeamCount provides a mock function with given fields:
func (_m *TeamStore) AnalyticsPublicTeamCount() (int64, *model.AppError) {
ret := _m.Called()
var r0 int64
if rf, ok := ret.Get(0).(func() int64); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(int64)
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func() *model.AppError); ok {
r1 = rf()
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// AnalyticsTeamCount provides a mock function with given fields:
func (_m *TeamStore) AnalyticsTeamCount() (int64, *model.AppError) {
ret := _m.Called()
@@ -252,6 +300,31 @@ func (_m *TeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*mod
return r0, r1
}
// GetAllPublicTeamPageListing provides a mock function with given fields: offset, limit
func (_m *TeamStore) GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {
ret := _m.Called(offset, limit)
var r0 []*model.Team
if rf, ok := ret.Get(0).(func(int, int) []*model.Team); ok {
r0 = rf(offset, limit)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Team)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(int, int) *model.AppError); ok {
r1 = rf(offset, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetAllTeamListing provides a mock function with given fields:
func (_m *TeamStore) GetAllTeamListing() ([]*model.Team, *model.AppError) {
ret := _m.Called()

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// TermsOfServiceStore is an autogenerated mock type for the TermsOfServiceStore type
type TermsOfServiceStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// TokenStore is an autogenerated mock type for the TokenStore type
type TokenStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// UserAccessTokenStore is an autogenerated mock type for the UserAccessTokenStore type
type UserAccessTokenStore struct {

View File

@@ -4,9 +4,11 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import store "github.com/mattermost/mattermost-server/store"
import (
model "github.com/mattermost/mattermost-server/model"
store "github.com/mattermost/mattermost-server/store"
mock "github.com/stretchr/testify/mock"
)
// UserStore is an autogenerated mock type for the UserStore type
type UserStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// UserTermsOfServiceStore is an autogenerated mock type for the UserTermsOfServiceStore type
type UserTermsOfServiceStore struct {

View File

@@ -4,8 +4,10 @@
package mocks
import mock "github.com/stretchr/testify/mock"
import model "github.com/mattermost/mattermost-server/model"
import (
model "github.com/mattermost/mattermost-server/model"
mock "github.com/stretchr/testify/mock"
)
// WebhookStore is an autogenerated mock type for the WebhookStore type
type WebhookStore struct {

View File

@@ -15,6 +15,14 @@ import (
"github.com/mattermost/mattermost-server/store"
)
func cleanupTeamStore(t *testing.T, ss store.Store) {
allTeams, err := ss.Team().GetAll()
for _, team := range allTeams {
ss.Team().PermanentDelete(team.Id)
}
assert.Nil(t, err)
}
func TestTeamStore(t *testing.T, ss store.Store) {
createDefaultRoles(t, ss)
@@ -31,8 +39,11 @@ func TestTeamStore(t *testing.T, ss store.Store) {
t.Run("GetAllTeamPageListing", func(t *testing.T) { testGetAllTeamPageListing(t, ss) })
t.Run("GetAllPrivateTeamListing", func(t *testing.T) { testGetAllPrivateTeamListing(t, ss) })
t.Run("GetAllPrivateTeamPageListing", func(t *testing.T) { testGetAllPrivateTeamPageListing(t, ss) })
t.Run("GetAllPublicTeamPageListing", func(t *testing.T) { testGetAllPublicTeamPageListing(t, ss) })
t.Run("Delete", func(t *testing.T) { testDelete(t, ss) })
t.Run("TeamCount", func(t *testing.T) { testTeamCount(t, ss) })
t.Run("TeamPublicCount", func(t *testing.T) { testPublicTeamCount(t, ss) })
t.Run("TeamPrivateCount", func(t *testing.T) { testPrivateTeamCount(t, ss) })
t.Run("TeamMembers", func(t *testing.T) { testTeamMembers(t, ss) })
t.Run("SaveTeamMemberMaxMembers", func(t *testing.T) { testSaveTeamMemberMaxMembers(t, ss) })
t.Run("GetTeamMember", func(t *testing.T) { testGetTeamMember(t, ss) })
@@ -678,6 +689,66 @@ func testGetAllPrivateTeamPageListing(t *testing.T, ss store.Store) {
}
}
func testGetAllPublicTeamPageListing(t *testing.T, ss store.Store) {
cleanupTeamStore(t, ss)
o1 := model.Team{}
o1.DisplayName = "DisplayName1"
o1.Name = "z-z-z" + model.NewId() + "b"
o1.Email = MakeEmail()
o1.Type = model.TEAM_OPEN
o1.AllowOpenInvite = true
t1, err := ss.Team().Save(&o1)
require.Nil(t, err)
o2 := model.Team{}
o2.DisplayName = "DisplayName2"
o2.Name = "zz" + model.NewId() + "b"
o2.Email = MakeEmail()
o2.Type = model.TEAM_OPEN
o2.AllowOpenInvite = false
_, err = ss.Team().Save(&o2)
require.Nil(t, err)
o3 := model.Team{}
o3.DisplayName = "DisplayName3"
o3.Name = "z-z-z" + model.NewId() + "b"
o3.Email = MakeEmail()
o3.Type = model.TEAM_INVITE
o3.AllowOpenInvite = true
t3, err := ss.Team().Save(&o3)
require.Nil(t, err)
o4 := model.Team{}
o4.DisplayName = "DisplayName4"
o4.Name = "zz" + model.NewId() + "b"
o4.Email = MakeEmail()
o4.Type = model.TEAM_INVITE
o4.AllowOpenInvite = false
_, err = ss.Team().Save(&o4)
require.Nil(t, err)
teams, err := ss.Team().GetAllPublicTeamPageListing(0, 10)
assert.Nil(t, err)
assert.Equal(t, []*model.Team{t1, t3}, teams)
o5 := model.Team{}
o5.DisplayName = "DisplayName5"
o5.Name = "z-z-z" + model.NewId() + "b"
o5.Email = MakeEmail()
o5.Type = model.TEAM_OPEN
o5.AllowOpenInvite = true
t5, err := ss.Team().Save(&o5)
require.Nil(t, err)
teams, err = ss.Team().GetAllPublicTeamPageListing(0, 4)
assert.Nil(t, err)
assert.Equal(t, []*model.Team{t1, t3, t5}, teams)
teams, err = ss.Team().GetAllPublicTeamPageListing(1, 1)
assert.Nil(t, err)
}
func testDelete(t *testing.T, ss store.Store) {
o1 := model.Team{}
o1.DisplayName = "DisplayName"
@@ -701,6 +772,76 @@ func testDelete(t *testing.T, ss store.Store) {
}
}
func testPublicTeamCount(t *testing.T, ss store.Store) {
cleanupTeamStore(t, ss)
o1 := model.Team{}
o1.DisplayName = "DisplayName"
o1.Name = "z-z-z" + model.NewId() + "b"
o1.Email = MakeEmail()
o1.Type = model.TEAM_OPEN
o1.AllowOpenInvite = true
_, err := ss.Team().Save(&o1)
require.Nil(t, err)
o2 := model.Team{}
o2.DisplayName = "DisplayName"
o2.Name = "z-z-z" + model.NewId() + "b"
o2.Email = MakeEmail()
o2.Type = model.TEAM_OPEN
o2.AllowOpenInvite = false
_, err = ss.Team().Save(&o2)
require.Nil(t, err)
o3 := model.Team{}
o3.DisplayName = "DisplayName"
o3.Name = "z-z-z" + model.NewId() + "b"
o3.Email = MakeEmail()
o3.Type = model.TEAM_OPEN
o3.AllowOpenInvite = true
_, err = ss.Team().Save(&o3)
require.Nil(t, err)
teamCount, err := ss.Team().AnalyticsPublicTeamCount()
require.Nil(t, err)
require.Equal(t, int64(2), teamCount, "should only be 1 team")
}
func testPrivateTeamCount(t *testing.T, ss store.Store) {
cleanupTeamStore(t, ss)
o1 := model.Team{}
o1.DisplayName = "DisplayName"
o1.Name = "z-z-z" + model.NewId() + "b"
o1.Email = MakeEmail()
o1.Type = model.TEAM_OPEN
o1.AllowOpenInvite = false
_, err := ss.Team().Save(&o1)
require.Nil(t, err)
o2 := model.Team{}
o2.DisplayName = "DisplayName"
o2.Name = "z-z-z" + model.NewId() + "b"
o2.Email = MakeEmail()
o2.Type = model.TEAM_OPEN
o2.AllowOpenInvite = true
_, err = ss.Team().Save(&o2)
require.Nil(t, err)
o3 := model.Team{}
o3.DisplayName = "DisplayName"
o3.Name = "z-z-z" + model.NewId() + "b"
o3.Email = MakeEmail()
o3.Type = model.TEAM_OPEN
o3.AllowOpenInvite = false
_, err = ss.Team().Save(&o3)
require.Nil(t, err)
teamCount, err := ss.Team().AnalyticsPrivateTeamCount()
require.Nil(t, err)
require.Equal(t, int64(2), teamCount, "should only be 1 team")
}
func testTeamCount(t *testing.T, ss store.Store) {
o1 := model.Team{}
o1.DisplayName = "DisplayName"