diff options
author | George Goldberg <george@gberg.me> | 2018-04-20 19:49:13 +0100 |
---|---|---|
committer | Martin Kraft <mkraft@users.noreply.github.com> | 2018-04-20 14:49:13 -0400 |
commit | cd55c44c8fd8f61cdb7cbfb57a588be82c7aa0ab (patch) | |
tree | 2979276d03b5bca72b549d7576eab104ceefd495 /store/storetest/team_store.go | |
parent | 853445dc2ea68f765faa04ad14618b04f1081c43 (diff) | |
download | chat-cd55c44c8fd8f61cdb7cbfb57a588be82c7aa0ab.tar.gz chat-cd55c44c8fd8f61cdb7cbfb57a588be82c7aa0ab.tar.bz2 chat-cd55c44c8fd8f61cdb7cbfb57a588be82c7aa0ab.zip |
MM-8796: Full implementation of "Schemes" in Store/Model/App layers. (#8357)
* Add Scheme model and stub store.
* Port ChannelStore to be Scheme aware.
* Make almost all the API/APP layer work with ChannelSchemes.
Only thing still hacky is UpdateChannelMemberRoles().
* Add basic SchemeStore implementation.
* Migrate UpdateChannelMemberRoles properly and fix tests.
* Update store tests and mocks so they work.
* Include creating default roles in Scheme create store function.
* Implement role deletion and start scheme deletion.
* Only use non-deleted roles for authorization.
* Add GetByScheme method to Team store.
* Add GetChannelsByScheme.
* Update store mocks.
* Implement scheme deletion in the store.
* Rename is valid function.
* Add offset and limit to queries to fetch teams and channels by scheme.
* Fix queries.
* Implement scheme awareness in Team store and add a migration.
* Tidy up ChannelStore mapping functions and add exhaustive unit tests.
* Add all missing i18n.
* Proper tests for TeamStore internal functions and fix them.
* Make additional TeamMember fields nullable.
* Make new ChannelMember fields nullable.
* Create new nullable columns without defaults.
* Make new fields in large tables nullalble.
* Fix empty list of TeamMembers.
* Deduplicate SQL queries.
* Fix spelling.
* Fix review comment.
* More review fixes.
* More review fixes.
Diffstat (limited to 'store/storetest/team_store.go')
-rw-r--r-- | store/storetest/team_store.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/store/storetest/team_store.go b/store/storetest/team_store.go index cab06f87f..ff79650d5 100644 --- a/store/storetest/team_store.go +++ b/store/storetest/team_store.go @@ -7,11 +7,15 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" ) func TestTeamStore(t *testing.T, ss store.Store) { + createDefaultRoles(t, ss) + t.Run("Save", func(t *testing.T) { testTeamStoreSave(t, ss) }) t.Run("Update", func(t *testing.T) { testTeamStoreUpdate(t, ss) }) t.Run("UpdateDisplayName", func(t *testing.T) { testTeamStoreUpdateDisplayName(t, ss) }) @@ -34,6 +38,7 @@ func TestTeamStore(t *testing.T, ss store.Store) { t.Run("GetChannelUnreadsForAllTeams", func(t *testing.T) { testGetChannelUnreadsForAllTeams(t, ss) }) t.Run("GetChannelUnreadsForTeam", func(t *testing.T) { testGetChannelUnreadsForTeam(t, ss) }) t.Run("UpdateLastTeamIconUpdate", func(t *testing.T) { testUpdateLastTeamIconUpdate(t, ss) }) + t.Run("GetTeamsByScheme", func(t *testing.T) { testGetTeamsByScheme(t, ss) }) } func testTeamStoreSave(t *testing.T, ss store.Store) { @@ -1029,3 +1034,67 @@ func testUpdateLastTeamIconUpdate(t *testing.T, ss store.Store) { t.Fatal("LastTeamIconUpdate not updated") } } + +func testGetTeamsByScheme(t *testing.T, ss store.Store) { + // Create some schemes. + s1 := &model.Scheme{ + Name: model.NewId(), + Description: model.NewId(), + Scope: model.SCHEME_SCOPE_TEAM, + } + + s2 := &model.Scheme{ + Name: model.NewId(), + Description: model.NewId(), + Scope: model.SCHEME_SCOPE_TEAM, + } + + s1 = (<-ss.Scheme().Save(s1)).Data.(*model.Scheme) + s2 = (<-ss.Scheme().Save(s2)).Data.(*model.Scheme) + + // Create and save some teams. + t1 := &model.Team{ + Name: model.NewId(), + DisplayName: model.NewId(), + Email: model.NewId() + "@nowhere.com", + Type: model.TEAM_OPEN, + SchemeId: &s1.Id, + } + + t2 := &model.Team{ + Name: model.NewId(), + DisplayName: model.NewId(), + Email: model.NewId() + "@nowhere.com", + Type: model.TEAM_OPEN, + SchemeId: &s1.Id, + } + + t3 := &model.Team{ + Name: model.NewId(), + DisplayName: model.NewId(), + Email: model.NewId() + "@nowhere.com", + Type: model.TEAM_OPEN, + } + + t1 = (<-ss.Team().Save(t1)).Data.(*model.Team) + t2 = (<-ss.Team().Save(t2)).Data.(*model.Team) + t3 = (<-ss.Team().Save(t3)).Data.(*model.Team) + + // Get the teams by a valid Scheme ID. + res1 := <-ss.Team().GetTeamsByScheme(s1.Id, 0, 100) + assert.Nil(t, res1.Err) + d1 := res1.Data.([]*model.Team) + assert.Len(t, d1, 2) + + // Get the teams by a valid Scheme ID where there aren't any matching Teams. + res2 := <-ss.Team().GetTeamsByScheme(s2.Id, 0, 100) + assert.Nil(t, res2.Err) + d2 := res2.Data.([]*model.Team) + assert.Len(t, d2, 0) + + // Get the teams by an invalid Scheme ID. + res3 := <-ss.Team().GetTeamsByScheme(model.NewId(), 0, 100) + assert.Nil(t, res3.Err) + d3 := res3.Data.([]*model.Team) + assert.Len(t, d3, 0) +} |