summaryrefslogtreecommitdiffstats
path: root/store/sql_channel_store_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-11-24 09:35:09 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2016-11-24 09:35:09 -0500
commit981ea33b8e10456bc279f36235c814305d01b243 (patch)
tree00fb6119d9ef16f60d4c0dbdaad1bd6dfbc347ed /store/sql_channel_store_test.go
parentc96ecae6da31aceabf29586cde872876b81d11d9 (diff)
downloadchat-981ea33b8e10456bc279f36235c814305d01b243.tar.gz
chat-981ea33b8e10456bc279f36235c814305d01b243.tar.bz2
chat-981ea33b8e10456bc279f36235c814305d01b243.zip
PLT-4403 Add server-based channel autocomplete, search and paging (#4585)
* Add more channel paging API * Add channel paging support to client * Add DB channel search functions * Add API for searching more channels * Add more channel search functionality to client * Add API for autocompleting channels * Add channel autocomplete functionality to the client * Move to be deprecated APIs to their own file * Final clean-up * Fixes related to feedback * Localization changes * Add unit as suffix to timeout constants
Diffstat (limited to 'store/sql_channel_store_test.go')
-rw-r--r--store/sql_channel_store_test.go214
1 files changed, 211 insertions, 3 deletions
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go
index 6776a438b..9b77639b0 100644
--- a/store/sql_channel_store_test.go
+++ b/store/sql_channel_store_test.go
@@ -309,7 +309,7 @@ func TestChannelStoreDelete(t *testing.T) {
t.Fatal("invalid number of channels")
}
- cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId)
+ cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100)
list = cresult.Data.(*model.ChannelList)
if len(*list) != 1 {
@@ -621,7 +621,10 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
o5.Type = model.CHANNEL_PRIVATE
Must(store.Channel().Save(&o5))
- cresult := <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId)
+ cresult := <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100)
+ if cresult.Err != nil {
+ t.Fatal(cresult.Err)
+ }
list := cresult.Data.(*model.ChannelList)
if len(*list) != 1 {
@@ -632,10 +635,38 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
t.Fatal("missing channel")
}
+ o6 := model.Channel{}
+ o6.TeamId = o1.TeamId
+ o6.DisplayName = "ChannelA"
+ o6.Name = "a" + model.NewId() + "b"
+ o6.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o6))
+
+ cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100)
+ list = cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 2 {
+ t.Fatal("wrong list length")
+ }
+
+ cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 1)
+ list = cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 1 {
+ t.Fatal("wrong list length")
+ }
+
+ cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 1, 1)
+ list = cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 1 {
+ t.Fatal("wrong list length")
+ }
+
if r1 := <-store.Channel().AnalyticsTypeCount(o1.TeamId, model.CHANNEL_OPEN); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- if r1.Data.(int64) != 2 {
+ if r1.Data.(int64) != 3 {
t.Log(r1.Data)
t.Fatal("wrong value")
}
@@ -1055,3 +1086,180 @@ func TestUpdateExtrasByUser(t *testing.T) {
t.Fatal("failed to update extras by user: %v", result.Err)
}
}
+
+func TestChannelStoreSearchMore(t *testing.T) {
+ Setup()
+
+ o1 := model.Channel{}
+ o1.TeamId = model.NewId()
+ o1.DisplayName = "ChannelA"
+ o1.Name = "a" + model.NewId() + "b"
+ o1.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o1))
+
+ o2 := model.Channel{}
+ o2.TeamId = model.NewId()
+ o2.DisplayName = "Channel2"
+ o2.Name = "a" + model.NewId() + "b"
+ o2.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o2))
+
+ m1 := model.ChannelMember{}
+ m1.ChannelId = o1.Id
+ m1.UserId = model.NewId()
+ m1.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m1))
+
+ m2 := model.ChannelMember{}
+ m2.ChannelId = o1.Id
+ m2.UserId = model.NewId()
+ m2.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m2))
+
+ m3 := model.ChannelMember{}
+ m3.ChannelId = o2.Id
+ m3.UserId = model.NewId()
+ m3.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m3))
+
+ o3 := model.Channel{}
+ o3.TeamId = o1.TeamId
+ o3.DisplayName = "ChannelA"
+ o3.Name = "a" + model.NewId() + "b"
+ o3.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o3))
+
+ o4 := model.Channel{}
+ o4.TeamId = o1.TeamId
+ o4.DisplayName = "ChannelB"
+ o4.Name = "a" + model.NewId() + "b"
+ o4.Type = model.CHANNEL_PRIVATE
+ Must(store.Channel().Save(&o4))
+
+ o5 := model.Channel{}
+ o5.TeamId = o1.TeamId
+ o5.DisplayName = "ChannelC"
+ o5.Name = "a" + model.NewId() + "b"
+ o5.Type = model.CHANNEL_PRIVATE
+ Must(store.Channel().Save(&o5))
+
+ if result := <-store.Channel().SearchMore(m1.UserId, o1.TeamId, "ChannelA"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) == 0 {
+ t.Fatal("should not be empty")
+ }
+
+ if (*channels)[0].Name != o3.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
+
+ if result := <-store.Channel().SearchMore(m1.UserId, o1.TeamId, o4.Name); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 0 {
+ t.Fatal("should be empty")
+ }
+ }
+
+ if result := <-store.Channel().SearchMore(m1.UserId, o1.TeamId, o3.Name); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) == 0 {
+ t.Fatal("should not be empty")
+ }
+
+ if (*channels)[0].Name != o3.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
+
+}
+
+func TestChannelStoreSearchInTeam(t *testing.T) {
+ Setup()
+
+ o1 := model.Channel{}
+ o1.TeamId = model.NewId()
+ o1.DisplayName = "ChannelA"
+ o1.Name = "a" + model.NewId() + "b"
+ o1.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o1))
+
+ o2 := model.Channel{}
+ o2.TeamId = model.NewId()
+ o2.DisplayName = "Channel2"
+ o2.Name = "a" + model.NewId() + "b"
+ o2.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o2))
+
+ m1 := model.ChannelMember{}
+ m1.ChannelId = o1.Id
+ m1.UserId = model.NewId()
+ m1.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m1))
+
+ m2 := model.ChannelMember{}
+ m2.ChannelId = o1.Id
+ m2.UserId = model.NewId()
+ m2.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m2))
+
+ m3 := model.ChannelMember{}
+ m3.ChannelId = o2.Id
+ m3.UserId = model.NewId()
+ m3.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m3))
+
+ o3 := model.Channel{}
+ o3.TeamId = o1.TeamId
+ o3.DisplayName = "ChannelA"
+ o3.Name = "a" + model.NewId() + "b"
+ o3.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o3))
+
+ o4 := model.Channel{}
+ o4.TeamId = o1.TeamId
+ o4.DisplayName = "ChannelB"
+ o4.Name = "a" + model.NewId() + "b"
+ o4.Type = model.CHANNEL_PRIVATE
+ Must(store.Channel().Save(&o4))
+
+ o5 := model.Channel{}
+ o5.TeamId = o1.TeamId
+ o5.DisplayName = "ChannelC"
+ o5.Name = "a" + model.NewId() + "b"
+ o5.Type = model.CHANNEL_PRIVATE
+ Must(store.Channel().Save(&o5))
+
+ if result := <-store.Channel().SearchInTeam(o1.TeamId, "ChannelA"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 2 {
+ t.Fatal("wrong length")
+ }
+ }
+
+ if result := <-store.Channel().SearchInTeam(o1.TeamId, ""); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) == 0 {
+ t.Fatal("should not be empty")
+ }
+ }
+
+ if result := <-store.Channel().SearchInTeam(o1.TeamId, "blargh"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 0 {
+ t.Fatal("should be empty")
+ }
+ }
+}