diff options
author | Chris <ccbrown112@gmail.com> | 2017-11-28 15:02:56 -0600 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-11-28 13:02:56 -0800 |
commit | b87fae646a624507f5b2c1270cae1d3585f589ac (patch) | |
tree | d81b683cda11b08ed04d7e2431b04a84a715d851 /store/storetest | |
parent | 27ba68a7894d5204b8d75dc7353774977d62fa15 (diff) | |
download | chat-b87fae646a624507f5b2c1270cae1d3585f589ac.tar.gz chat-b87fae646a624507f5b2c1270cae1d3585f589ac.tar.bz2 chat-b87fae646a624507f5b2c1270cae1d3585f589ac.zip |
PLT-5458: If someone posts a channel link to channel_A that you don't belong to, it doesn't render properly (#7833)
* add channel link hints to post props
* optimization
* update regex, add unit test
* fix rebase issue
Diffstat (limited to 'store/storetest')
-rw-r--r-- | store/storetest/channel_store.go | 54 | ||||
-rw-r--r-- | store/storetest/mocks/ChannelStore.go | 16 |
2 files changed, 70 insertions, 0 deletions
diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index 1189fd976..853de67d8 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -4,10 +4,12 @@ package storetest import ( + "sort" "testing" "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" @@ -24,6 +26,7 @@ func TestChannelStore(t *testing.T, ss store.Store) { t.Run("Restore", func(t *testing.T) { testChannelStoreRestore(t, ss) }) t.Run("Delete", func(t *testing.T) { testChannelStoreDelete(t, ss) }) t.Run("GetByName", func(t *testing.T) { testChannelStoreGetByName(t, ss) }) + t.Run("GetByNames", func(t *testing.T) { testChannelStoreGetByNames(t, ss) }) t.Run("GetDeletedByName", func(t *testing.T) { testChannelStoreGetDeletedByName(t, ss) }) t.Run("GetDeleted", func(t *testing.T) { testChannelStoreGetDeleted(t, ss) }) t.Run("ChannelMemberStore", func(t *testing.T) { testChannelMemberStore(t, ss) }) @@ -550,6 +553,57 @@ func testChannelStoreGetByName(t *testing.T, ss store.Store) { } } +func testChannelStoreGetByNames(t *testing.T, ss store.Store) { + o1 := model.Channel{ + TeamId: model.NewId(), + DisplayName: "Name", + Name: "zz" + model.NewId() + "b", + Type: model.CHANNEL_OPEN, + } + store.Must(ss.Channel().Save(&o1, -1)) + + o2 := model.Channel{ + TeamId: o1.TeamId, + DisplayName: "Name", + Name: "zz" + model.NewId() + "b", + Type: model.CHANNEL_OPEN, + } + store.Must(ss.Channel().Save(&o2, -1)) + + for index, tc := range []struct { + TeamId string + Names []string + ExpectedIds []string + }{ + {o1.TeamId, []string{o1.Name}, []string{o1.Id}}, + {o1.TeamId, []string{o1.Name, o2.Name}, []string{o1.Id, o2.Id}}, + {o1.TeamId, nil, nil}, + {o1.TeamId, []string{"foo"}, nil}, + {o1.TeamId, []string{o1.Name, "foo", o2.Name, o2.Name}, []string{o1.Id, o2.Id}}, + {"", []string{o1.Name, "foo", o2.Name, o2.Name}, []string{o1.Id, o2.Id}}, + {"asd", []string{o1.Name, "foo", o2.Name, o2.Name}, nil}, + } { + r := <-ss.Channel().GetByNames(tc.TeamId, tc.Names, true) + require.Nil(t, r.Err) + channels := r.Data.([]*model.Channel) + var ids []string + for _, channel := range channels { + ids = append(ids, channel.Id) + } + sort.Strings(ids) + sort.Strings(tc.ExpectedIds) + assert.Equal(t, tc.ExpectedIds, ids, "tc %v", index) + } + + store.Must(ss.Channel().Delete(o1.Id, model.GetMillis())) + store.Must(ss.Channel().Delete(o2.Id, model.GetMillis())) + + r := <-ss.Channel().GetByNames(o1.TeamId, []string{o1.Name}, false) + require.Nil(t, r.Err) + channels := r.Data.([]*model.Channel) + assert.Len(t, channels, 0) +} + func testChannelStoreGetDeletedByName(t *testing.T, ss store.Store) { o1 := model.Channel{} o1.TeamId = model.NewId() diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index 2ea5256d7..c878d602b 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -189,6 +189,22 @@ func (_m *ChannelStore) GetByNameIncludeDeleted(team_id string, name string, all return r0 } +// GetByNames provides a mock function with given fields: team_id, names, allowFromCache +func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCache bool) store.StoreChannel { + ret := _m.Called(team_id, names, allowFromCache) + + var r0 store.StoreChannel + if rf, ok := ret.Get(0).(func(string, []string, bool) store.StoreChannel); ok { + r0 = rf(team_id, names, allowFromCache) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.StoreChannel) + } + } + + return r0 +} + // GetChannelCounts provides a mock function with given fields: teamId, userId func (_m *ChannelStore) GetChannelCounts(teamId string, userId string) store.StoreChannel { ret := _m.Called(teamId, userId) |