From f82667f3b86202dafff3a2a4ea56aec74c80316d Mon Sep 17 00:00:00 2001 From: enahum Date: Thu, 27 Oct 2016 12:24:30 -0300 Subject: PLT-4430 improve slow channel switching (#4331) * PLT-4430 improve slow channel switching * Update client side unit tests * Convert getChannelsUnread to getMyChannelMembers and address other feedback * Pull channel members on websocket reconnect --- api/channel_test.go | 56 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'api/channel_test.go') diff --git a/api/channel_test.go b/api/channel_test.go index 4835ee9b7..83bb732dd 100644 --- a/api/channel_test.go +++ b/api/channel_test.go @@ -35,7 +35,7 @@ func TestCreateChannel(t *testing.T) { rget := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList) nameMatch := false - for _, c := range rget.Channels { + for _, c := range *rget { if c.Name == channel.Name { nameMatch = true } @@ -240,8 +240,8 @@ func TestUpdateChannel(t *testing.T) { } rget := Client.Must(Client.GetChannels("")) - data := rget.Data.(*model.ChannelList) - for _, c := range data.Channels { + channels := rget.Data.(*model.ChannelList) + for _, c := range *channels { if c.Name == model.DEFAULT_CHANNEL { c.Header = "new header" c.Name = "pseudo-square" @@ -654,13 +654,13 @@ func TestGetChannel(t *testing.T) { channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel) rget := Client.Must(Client.GetChannels("")) - data := rget.Data.(*model.ChannelList) + channels := rget.Data.(*model.ChannelList) - if data.Channels[0].DisplayName != channel1.DisplayName { + if (*channels)[0].DisplayName != channel1.DisplayName { t.Fatal("full name didn't match") } - if data.Channels[1].DisplayName != channel2.DisplayName { + if (*channels)[1].DisplayName != channel2.DisplayName { t.Fatal("full name didn't match") } @@ -717,13 +717,13 @@ func TestGetMoreChannel(t *testing.T) { th.LoginBasic2() rget := Client.Must(Client.GetMoreChannels("")) - data := rget.Data.(*model.ChannelList) + channels := rget.Data.(*model.ChannelList) - if data.Channels[0].DisplayName != channel1.DisplayName { + if (*channels)[0].DisplayName != channel1.DisplayName { t.Fatal("full name didn't match") } - if data.Channels[1].DisplayName != channel2.DisplayName { + if (*channels)[1].DisplayName != channel2.DisplayName { t.Fatal("full name didn't match") } @@ -770,6 +770,30 @@ func TestGetChannelCounts(t *testing.T) { } +func TestGetMyChannelMembers(t *testing.T) { + th := Setup().InitBasic() + Client := th.BasicClient + team := th.BasicTeam + + channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} + channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) + + channel2 := &model.Channel{DisplayName: "B Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} + channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel) + + if result, err := Client.GetMyChannelMembers(); err != nil { + t.Fatal(err) + } else { + members := result.Data.(*model.ChannelMembers) + + // town-square, off-topic, basic test channel, channel1, channel2 + if len(*members) != 5 { + t.Fatal("wrong number of members", len(*members)) + } + } + +} + func TestJoinChannelById(t *testing.T) { th := Setup().InitBasic() Client := th.BasicClient @@ -905,7 +929,7 @@ func TestLeaveChannel(t *testing.T) { rget := Client.Must(Client.GetChannels("")) cdata := rget.Data.(*model.ChannelList) - for _, c := range cdata.Channels { + for _, c := range *cdata { if c.Name == model.DEFAULT_CHANNEL { if _, err := Client.LeaveChannel(c.Id); err == nil { t.Fatal("should have errored on leaving default channel") @@ -969,7 +993,7 @@ func TestDeleteChannel(t *testing.T) { rget := Client.Must(Client.GetChannels("")) cdata := rget.Data.(*model.ChannelList) - for _, c := range cdata.Channels { + for _, c := range *cdata { if c.Name == model.DEFAULT_CHANNEL { if _, err := Client.DeleteChannel(c.Id); err == nil { t.Fatal("should have errored on deleting default channel") @@ -1249,7 +1273,7 @@ func TestUpdateNotifyProps(t *testing.T) { data["user_id"] = user.Id data["desktop"] = model.CHANNEL_NOTIFY_MENTION - timeBeforeUpdate := model.GetMillis() + //timeBeforeUpdate := model.GetMillis() time.Sleep(100 * time.Millisecond) // test updating desktop @@ -1261,14 +1285,6 @@ func TestUpdateNotifyProps(t *testing.T) { t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps["mark_unread"]) } - rget := Client.Must(Client.GetChannels("")) - rdata := rget.Data.(*model.ChannelList) - if len(rdata.Members) == 0 || rdata.Members[channel1.Id].NotifyProps["desktop"] != data["desktop"] { - t.Fatal("NotifyProps[\"desktop\"] did not update properly") - } else if rdata.Members[channel1.Id].LastUpdateAt <= timeBeforeUpdate { - t.Fatal("LastUpdateAt did not update") - } - // test an empty update delete(data, "desktop") -- cgit v1.2.3-1-g7c22