diff options
Diffstat (limited to 'store/sql_channel_store_test.go')
-rw-r--r-- | store/sql_channel_store_test.go | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go index f6a0fb713..695991bf7 100644 --- a/store/sql_channel_store_test.go +++ b/store/sql_channel_store_test.go @@ -339,15 +339,15 @@ func TestChannelMemberStore(t *testing.T) { t.Fatal("Member update time incorrect") } - members := (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember) - if len(members) != 2 { + count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64) + if count != 2 { t.Fatal("should have saved 2 members") } Must(store.Channel().RemoveMember(o2.ChannelId, o2.UserId)) - members = (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember) - if len(members) != 1 { + count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64) + if count != 1 { t.Fatal("should have removed 1 member") } @@ -379,6 +379,63 @@ func TestChannelMemberStore(t *testing.T) { } } +func TestChannelDeleteMemberStore(t *testing.T) { + Setup() + + c1 := model.Channel{} + c1.TeamId = model.NewId() + c1.DisplayName = "NameName" + c1.Name = "a" + model.NewId() + "b" + c1.Type = model.CHANNEL_OPEN + c1 = *Must(store.Channel().Save(&c1)).(*model.Channel) + + c1t1 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel) + t1 := c1t1.ExtraUpdateAt + + u1 := model.User{} + u1.TeamId = model.NewId() + u1.Email = model.NewId() + u1.Nickname = model.NewId() + Must(store.User().Save(&u1)) + + u2 := model.User{} + u2.TeamId = model.NewId() + u2.Email = model.NewId() + u2.Nickname = model.NewId() + Must(store.User().Save(&u2)) + + o1 := model.ChannelMember{} + o1.ChannelId = c1.Id + o1.UserId = u1.Id + o1.NotifyProps = model.GetDefaultChannelNotifyProps() + Must(store.Channel().SaveMember(&o1)) + + o2 := model.ChannelMember{} + o2.ChannelId = c1.Id + o2.UserId = u2.Id + o2.NotifyProps = model.GetDefaultChannelNotifyProps() + Must(store.Channel().SaveMember(&o2)) + + c1t2 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel) + t2 := c1t2.ExtraUpdateAt + + if t2 <= t1 { + t.Fatal("Member update time incorrect") + } + + count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64) + if count != 2 { + t.Fatal("should have saved 2 members") + } + + Must(store.Channel().PermanentDeleteMembersByUser(o2.UserId)) + + count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64) + if count != 1 { + t.Fatal("should have removed 1 member") + } +} + func TestChannelStorePermissionsTo(t *testing.T) { Setup() |