summaryrefslogtreecommitdiffstats
path: root/store/storetest/channel_store.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-04-20 19:49:13 +0100
committerMartin Kraft <mkraft@users.noreply.github.com>2018-04-20 14:49:13 -0400
commitcd55c44c8fd8f61cdb7cbfb57a588be82c7aa0ab (patch)
tree2979276d03b5bca72b549d7576eab104ceefd495 /store/storetest/channel_store.go
parent853445dc2ea68f765faa04ad14618b04f1081c43 (diff)
downloadchat-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/channel_store.go')
-rw-r--r--store/storetest/channel_store.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go
index 481631783..7427c816c 100644
--- a/store/storetest/channel_store.go
+++ b/store/storetest/channel_store.go
@@ -16,6 +16,8 @@ import (
)
func TestChannelStore(t *testing.T, ss store.Store) {
+ createDefaultRoles(t, ss)
+
t.Run("Save", func(t *testing.T) { testChannelStoreSave(t, ss) })
t.Run("SaveDirectChannel", func(t *testing.T) { testChannelStoreSaveDirectChannel(t, ss) })
t.Run("CreateDirectChannel", func(t *testing.T) { testChannelStoreCreateDirectChannel(t, ss) })
@@ -49,6 +51,8 @@ func TestChannelStore(t *testing.T, ss store.Store) {
t.Run("AnalyticsDeletedTypeCount", func(t *testing.T) { testChannelStoreAnalyticsDeletedTypeCount(t, ss) })
t.Run("GetPinnedPosts", func(t *testing.T) { testChannelStoreGetPinnedPosts(t, ss) })
t.Run("MaxChannelsPerTeam", func(t *testing.T) { testChannelStoreMaxChannelsPerTeam(t, ss) })
+ t.Run("GetChannelsByScheme", func(t *testing.T) { testChannelStoreGetChannelsByScheme(t, ss) })
+
}
func testChannelStoreSave(t *testing.T, ss store.Store) {
@@ -2186,3 +2190,67 @@ func testChannelStoreMaxChannelsPerTeam(t *testing.T, ss store.Store) {
result = <-ss.Channel().Save(channel, 1)
assert.Nil(t, result.Err)
}
+
+func testChannelStoreGetChannelsByScheme(t *testing.T, ss store.Store) {
+ // Create some schemes.
+ s1 := &model.Scheme{
+ Name: model.NewId(),
+ Description: model.NewId(),
+ Scope: model.SCHEME_SCOPE_CHANNEL,
+ }
+
+ s2 := &model.Scheme{
+ Name: model.NewId(),
+ Description: model.NewId(),
+ Scope: model.SCHEME_SCOPE_CHANNEL,
+ }
+
+ s1 = (<-ss.Scheme().Save(s1)).Data.(*model.Scheme)
+ s2 = (<-ss.Scheme().Save(s2)).Data.(*model.Scheme)
+
+ // Create and save some teams.
+ c1 := &model.Channel{
+ TeamId: model.NewId(),
+ DisplayName: "Name",
+ Name: model.NewId(),
+ Type: model.CHANNEL_OPEN,
+ SchemeId: &s1.Id,
+ }
+
+ c2 := &model.Channel{
+ TeamId: model.NewId(),
+ DisplayName: "Name",
+ Name: model.NewId(),
+ Type: model.CHANNEL_OPEN,
+ SchemeId: &s1.Id,
+ }
+
+ c3 := &model.Channel{
+ TeamId: model.NewId(),
+ DisplayName: "Name",
+ Name: model.NewId(),
+ Type: model.CHANNEL_OPEN,
+ }
+
+ c1 = (<-ss.Channel().Save(c1, 100)).Data.(*model.Channel)
+ c2 = (<-ss.Channel().Save(c2, 100)).Data.(*model.Channel)
+ c3 = (<-ss.Channel().Save(c3, 100)).Data.(*model.Channel)
+
+ // Get the channels by a valid Scheme ID.
+ res1 := <-ss.Channel().GetChannelsByScheme(s1.Id, 0, 100)
+ assert.Nil(t, res1.Err)
+ d1 := res1.Data.([]*model.Channel)
+ assert.Len(t, d1, 2)
+
+ // Get the channels by a valid Scheme ID where there aren't any matching Channel.
+ res2 := <-ss.Channel().GetChannelsByScheme(s2.Id, 0, 100)
+ assert.Nil(t, res2.Err)
+ d2 := res2.Data.([]*model.Channel)
+ assert.Len(t, d2, 0)
+
+ // Get the channels by an invalid Scheme ID.
+ res3 := <-ss.Channel().GetChannelsByScheme(model.NewId(), 0, 100)
+ assert.Nil(t, res3.Err)
+ d3 := res3.Data.([]*model.Channel)
+ assert.Len(t, d3, 0)
+}