summaryrefslogtreecommitdiffstats
path: root/store/sql_channel_store_test.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2016-06-06 13:03:56 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2016-06-06 13:03:56 -0400
commit384d0eb245e2aa325fdcfe2d8ee22a40c91af589 (patch)
treec61bbf3241625d766fa81fbebf7395db3ef3521d /store/sql_channel_store_test.go
parent2c42294bbcab3cd5cfdce9604e5872fe4a12e538 (diff)
downloadchat-384d0eb245e2aa325fdcfe2d8ee22a40c91af589.tar.gz
chat-384d0eb245e2aa325fdcfe2d8ee22a40c91af589.tar.bz2
chat-384d0eb245e2aa325fdcfe2d8ee22a40c91af589.zip
PLT-2559 Always return successful when trying to join a channel that the user is already a member of (#3265)
* Added unit tests for SqlChannelStore.GetMember * Fixed api routes for accessing channels by name when the name includes an underscore * Changed join channel API to always return successful when the user is already a member of the channel
Diffstat (limited to 'store/sql_channel_store_test.go')
-rw-r--r--store/sql_channel_store_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go
index 1b3ea6fe5..2b284d06e 100644
--- a/store/sql_channel_store_test.go
+++ b/store/sql_channel_store_test.go
@@ -778,6 +778,66 @@ func TestChannelStoreIncrementMentionCount(t *testing.T) {
}
}
+func TestGetMember(t *testing.T) {
+ Setup()
+
+ userId := model.NewId()
+
+ c1 := &model.Channel{
+ TeamId: model.NewId(),
+ DisplayName: model.NewId(),
+ Name: model.NewId(),
+ Type: model.CHANNEL_OPEN,
+ }
+ Must(store.Channel().Save(c1))
+
+ c2 := &model.Channel{
+ TeamId: c1.TeamId,
+ DisplayName: model.NewId(),
+ Name: model.NewId(),
+ Type: model.CHANNEL_OPEN,
+ }
+ Must(store.Channel().Save(c2))
+
+ m1 := &model.ChannelMember{
+ ChannelId: c1.Id,
+ UserId: userId,
+ NotifyProps: model.GetDefaultChannelNotifyProps(),
+ }
+ Must(store.Channel().SaveMember(m1))
+
+ m2 := &model.ChannelMember{
+ ChannelId: c2.Id,
+ UserId: userId,
+ NotifyProps: model.GetDefaultChannelNotifyProps(),
+ }
+ Must(store.Channel().SaveMember(m2))
+
+ if result := <-store.Channel().GetMember(model.NewId(), userId); result.Err == nil {
+ t.Fatal("should've failed to get member for non-existant channel")
+ }
+
+ if result := <-store.Channel().GetMember(c1.Id, model.NewId()); result.Err == nil {
+ t.Fatal("should've failed to get member for non-existant user")
+ }
+
+ if result := <-store.Channel().GetMember(c1.Id, userId); result.Err != nil {
+ t.Fatal("shouldn't have errored when getting member", result.Err)
+ } else if member := result.Data.(model.ChannelMember); member.ChannelId != c1.Id {
+ t.Fatal("should've gotten member of channel 1")
+ } else if member.UserId != userId {
+ t.Fatal("should've gotten member for user")
+ }
+
+ if result := <-store.Channel().GetMember(c2.Id, userId); result.Err != nil {
+ t.Fatal("shouldn't have errored when getting member", result.Err)
+ } else if member := result.Data.(model.ChannelMember); member.ChannelId != c2.Id {
+ t.Fatal("should've gotten member of channel 2")
+ } else if member.UserId != userId {
+ t.Fatal("should've gotten member for user")
+ }
+}
+
func TestGetMemberCount(t *testing.T) {
Setup()