summaryrefslogtreecommitdiffstats
path: root/store/storetest/channel_store.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-10-11 17:20:27 +0800
committerGitHub <noreply@github.com>2017-10-11 17:20:27 +0800
commit521e27f4ace125b47879b38edbad07d7c21a54e6 (patch)
tree680b6f48a4dfd8bb91063ad638e11be3e56e1259 /store/storetest/channel_store.go
parent66b07a72ce45ce12f1840e0f74f26ea2a9b8105f (diff)
downloadchat-521e27f4ace125b47879b38edbad07d7c21a54e6.tar.gz
chat-521e27f4ace125b47879b38edbad07d7c21a54e6.tar.bz2
chat-521e27f4ace125b47879b38edbad07d7c21a54e6.zip
[PLT-7764] Fix in:channel search when channel name/displayname includes `-` (#7603)
* fix in:channel search when channel name/displayname includes `-` * fix failing test in PostgreSQL * add lowercase indexes of channel's name and displayname to postgresql, and add unit tests
Diffstat (limited to 'store/storetest/channel_store.go')
-rw-r--r--store/storetest/channel_store.go120
1 files changed, 120 insertions, 0 deletions
diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go
index 53d81bdc0..52cfbbbd0 100644
--- a/store/storetest/channel_store.go
+++ b/store/storetest/channel_store.go
@@ -1673,6 +1673,27 @@ func testChannelStoreSearchMore(t *testing.T, ss store.Store) {
o5.Type = model.CHANNEL_PRIVATE
store.Must(ss.Channel().Save(&o5))
+ o6 := model.Channel{}
+ o6.TeamId = o1.TeamId
+ o6.DisplayName = "Off-Topic"
+ o6.Name = "off-topic"
+ o6.Type = model.CHANNEL_OPEN
+ store.Must(ss.Channel().Save(&o6))
+
+ o7 := model.Channel{}
+ o7.TeamId = o1.TeamId
+ o7.DisplayName = "Off-Set"
+ o7.Name = "off-set"
+ o7.Type = model.CHANNEL_OPEN
+ store.Must(ss.Channel().Save(&o7))
+
+ o8 := model.Channel{}
+ o8.TeamId = o1.TeamId
+ o8.DisplayName = "Off-Limit"
+ o8.Name = "off-limit"
+ o8.Type = model.CHANNEL_PRIVATE
+ store.Must(ss.Channel().Save(&o8))
+
if result := <-ss.Channel().SearchMore(m1.UserId, o1.TeamId, "ChannelA"); result.Err != nil {
t.Fatal(result.Err)
} else {
@@ -1708,6 +1729,45 @@ func testChannelStoreSearchMore(t *testing.T, ss store.Store) {
}
}
+ if result := <-ss.Channel().SearchMore(m1.UserId, o1.TeamId, "off-"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 2 {
+ t.Fatal("should return 2 channels, not including private channel")
+ }
+
+ if (*channels)[0].Name != o7.Name {
+ t.Fatal("wrong channel returned")
+ }
+
+ if (*channels)[1].Name != o6.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
+
+ if result := <-ss.Channel().SearchMore(m1.UserId, o1.TeamId, "off-topic"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 1 {
+ t.Fatal("should return 1 channel")
+ }
+
+ if (*channels)[0].Name != o6.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
+
+ if result := <-ss.Channel().SearchMore(m1.UserId, o1.TeamId, "off-topics"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 0 {
+ t.Logf("%v\n", *channels)
+ t.Fatal("should be empty")
+ }
+ }
}
func testChannelStoreSearchInTeam(t *testing.T, ss store.Store) {
@@ -1764,6 +1824,27 @@ func testChannelStoreSearchInTeam(t *testing.T, ss store.Store) {
o5.Type = model.CHANNEL_PRIVATE
store.Must(ss.Channel().Save(&o5))
+ o6 := model.Channel{}
+ o6.TeamId = o1.TeamId
+ o6.DisplayName = "Off-Topic"
+ o6.Name = "off-topic"
+ o6.Type = model.CHANNEL_OPEN
+ store.Must(ss.Channel().Save(&o6))
+
+ o7 := model.Channel{}
+ o7.TeamId = o1.TeamId
+ o7.DisplayName = "Off-Set"
+ o7.Name = "off-set"
+ o7.Type = model.CHANNEL_OPEN
+ store.Must(ss.Channel().Save(&o7))
+
+ o8 := model.Channel{}
+ o8.TeamId = o1.TeamId
+ o8.DisplayName = "Off-Limit"
+ o8.Name = "off-limit"
+ o8.Type = model.CHANNEL_PRIVATE
+ store.Must(ss.Channel().Save(&o8))
+
if result := <-ss.Channel().SearchInTeam(o1.TeamId, "ChannelA"); result.Err != nil {
t.Fatal(result.Err)
} else {
@@ -1790,6 +1871,45 @@ func testChannelStoreSearchInTeam(t *testing.T, ss store.Store) {
t.Fatal("should be empty")
}
}
+
+ if result := <-ss.Channel().SearchInTeam(o1.TeamId, "off-"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 2 {
+ t.Fatal("should return 2 channels, not including private channel")
+ }
+
+ if (*channels)[0].Name != o7.Name {
+ t.Fatal("wrong channel returned")
+ }
+
+ if (*channels)[1].Name != o6.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
+
+ if result := <-ss.Channel().SearchInTeam(o1.TeamId, "off-topic"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 1 {
+ t.Fatal("should return 1 channel")
+ }
+
+ if (*channels)[0].Name != o6.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
+
+ if result := <-ss.Channel().SearchInTeam(o1.TeamId, "off-topics"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 0 {
+ t.Fatal("should be empty")
+ }
+ }
}
func testChannelStoreGetMembersByIds(t *testing.T, ss store.Store) {