mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[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:
12
api4/team.go
12
api4/team.go
@@ -740,9 +740,17 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teams, err = c.App.GetAllTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
}
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PRIVATE_TEAMS) {
|
||||
teams, err = c.App.GetAllPrivateTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
if c.Params.IncludeTotalCount {
|
||||
teamsWithCount, err = c.App.GetAllPrivateTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
} else {
|
||||
teams, err = c.App.GetAllPrivateTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
}
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
teams, err = c.App.GetAllPublicTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
if c.Params.IncludeTotalCount {
|
||||
teamsWithCount, err = c.App.GetAllPublicTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
} else {
|
||||
teams, err = c.App.GetAllPublicTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -621,6 +621,10 @@ func TestGetAllTeams(t *testing.T) {
|
||||
team3, resp = Client.CreateTeam(team3)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
team4 := &model.Team{DisplayName: "Name4", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
|
||||
team4, resp = Client.CreateTeam(team4)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
testCases := []struct {
|
||||
Name string
|
||||
Page int
|
||||
@@ -663,14 +667,14 @@ func TestGetAllTeams(t *testing.T) {
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PRIVATE_TEAMS.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team3.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team3.Id, team4.Id},
|
||||
},
|
||||
{
|
||||
Name: "Get all teams",
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PUBLIC_TEAMS.Id, model.PERMISSION_LIST_PRIVATE_TEAMS.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id, team4.Id},
|
||||
},
|
||||
{
|
||||
Name: "Get no teams because permissions",
|
||||
@@ -684,9 +688,27 @@ func TestGetAllTeams(t *testing.T) {
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PUBLIC_TEAMS.Id, model.PERMISSION_LIST_PRIVATE_TEAMS.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id, team4.Id},
|
||||
WithCount: true,
|
||||
ExpectedCount: 4,
|
||||
ExpectedCount: 5,
|
||||
},
|
||||
{
|
||||
Name: "Get all public teams with count",
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PUBLIC_TEAMS.Id},
|
||||
ExpectedTeams: []string{team1.Id, team2.Id},
|
||||
WithCount: true,
|
||||
ExpectedCount: 2,
|
||||
},
|
||||
{
|
||||
Name: "Get all private teams with count",
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PRIVATE_TEAMS.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team3.Id, team4.Id},
|
||||
WithCount: true,
|
||||
ExpectedCount: 3,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2310,7 +2332,9 @@ func TestInviteGuestsToTeam(t *testing.T) {
|
||||
defer func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableEmailInvitations = &enableEmailInvitations })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.RestrictCreationToDomains = restrictCreationToDomains })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GuestAccountsSettings.RestrictCreationToDomains = guestRestrictCreationToDomains })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.GuestAccountsSettings.RestrictCreationToDomains = guestRestrictCreationToDomains
|
||||
})
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GuestAccountsSettings.Enable = &enableGuestAccounts })
|
||||
}()
|
||||
|
||||
|
||||
24
app/team.go
24
app/team.go
@@ -683,6 +683,18 @@ func (a *App) GetAllPrivateTeamsPage(offset int, limit int) ([]*model.Team, *mod
|
||||
return a.Srv.Store.Team().GetAllPrivateTeamPageListing(offset, limit)
|
||||
}
|
||||
|
||||
func (a *App) GetAllPrivateTeamsPageWithCount(offset int, limit int) (*model.TeamsWithCount, *model.AppError) {
|
||||
totalCount, err := a.Srv.Store.Team().AnalyticsPrivateTeamCount()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teams, err := a.Srv.Store.Team().GetAllPrivateTeamPageListing(offset, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &model.TeamsWithCount{Teams: teams, TotalCount: totalCount}, nil
|
||||
}
|
||||
|
||||
func (a *App) GetAllPublicTeams() ([]*model.Team, *model.AppError) {
|
||||
return a.Srv.Store.Team().GetAllTeamListing()
|
||||
}
|
||||
@@ -691,6 +703,18 @@ func (a *App) GetAllPublicTeamsPage(offset int, limit int) ([]*model.Team, *mode
|
||||
return a.Srv.Store.Team().GetAllTeamPageListing(offset, limit)
|
||||
}
|
||||
|
||||
func (a *App) GetAllPublicTeamsPageWithCount(offset int, limit int) (*model.TeamsWithCount, *model.AppError) {
|
||||
totalCount, err := a.Srv.Store.Team().AnalyticsPublicTeamCount()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teams, err := a.Srv.Store.Team().GetAllPublicTeamPageListing(offset, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &model.TeamsWithCount{Teams: teams, TotalCount: totalCount}, nil
|
||||
}
|
||||
|
||||
func (a *App) SearchAllTeams(term string) ([]*model.Team, *model.AppError) {
|
||||
return a.Srv.Store.Team().SearchAll(term)
|
||||
}
|
||||
|
||||
@@ -6678,6 +6678,14 @@
|
||||
"id": "store.sql_team.analytics_get_team_count_for_scheme.app_error",
|
||||
"translation": "Unable to get the channel count for the scheme."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_team.analytics_private_team_count.app_error",
|
||||
"translation": "Unable to count the private teams"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_team.analytics_public_team_count.app_error",
|
||||
"translation": "Unable to count the public teams"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_team.analytics_team_count.app_error",
|
||||
"translation": "Unable to count the teams"
|
||||
|
||||
@@ -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{}{})
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user