From ba6e370ca71abacaa30234cb164427d27c86df13 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 21 Dec 2016 16:35:01 -0500 Subject: PLT-5012 Combine updateLastViewedAt, setLastViewedAt and setActiveChannel into a single API (#4840) * Combine updateLastViewedAt, setLastViewedAt and setActiveChannel into a single API * Remove preference DB writes --- api/channel_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'api/channel_test.go') diff --git a/api/channel_test.go b/api/channel_test.go index ae4573c9c..d24a6d603 100644 --- a/api/channel_test.go +++ b/api/channel_test.go @@ -724,8 +724,9 @@ func TestGetChannel(t *testing.T) { t.Fatal("cache should be empty") } - if _, err := Client.UpdateLastViewedAt(channel2.Id, true); err != nil { - t.Fatal(err) + view := model.ChannelView{ChannelId: channel2.Id, PrevChannelId: channel1.Id} + if _, resp := Client.ViewChannel(view); resp.Error != nil { + t.Fatal(resp.Error) } if resp, err := Client.GetChannel(channel1.Id, ""); err != nil { @@ -1735,3 +1736,44 @@ func TestGetChannelByName(t *testing.T) { t.Fatal("Should fail due to not enough permissions") } } + +func TestViewChannel(t *testing.T) { + th := Setup().InitBasic() + Client := th.BasicClient + + view := model.ChannelView{ + ChannelId: th.BasicChannel.Id, + } + + if _, resp := Client.ViewChannel(view); resp.Error != nil { + t.Fatal(resp.Error) + } + + view.PrevChannelId = th.BasicChannel.Id + + if _, resp := Client.ViewChannel(view); resp.Error != nil { + t.Fatal(resp.Error) + } + + view.PrevChannelId = "" + view.Time = 1234567890 + + if _, resp := Client.ViewChannel(view); resp.Error != nil { + t.Fatal(resp.Error) + } + + view.PrevChannelId = "junk" + view.Time = 0 + + if _, resp := Client.ViewChannel(view); resp.Error != nil { + t.Fatal(resp.Error) + } + + rdata := Client.Must(Client.GetChannel(th.BasicChannel.Id, "")).Data.(*model.ChannelData) + + if rdata.Channel.TotalMsgCount != rdata.Member.MsgCount { + t.Log(rdata.Channel.TotalMsgCount) + t.Log(rdata.Member.MsgCount) + t.Fatal("message counts don't match") + } +} -- cgit v1.2.3-1-g7c22