MM-30048 added thread related socket messages (#16234)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Eli Yukelzon
2020-11-20 11:00:52 +02:00
коммит произвёл GitHub
родитель 7b515d27f2
Коммит cf4df5fcd2
11 изменённых файлов: 190 добавлений и 26 удалений

Просмотреть файл

@@ -5401,6 +5401,98 @@ func TestGetThreadsForUser(t *testing.T) {
})
}
func TestThreadSocketEvents(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.ThreadAutoFollow = true
*cfg.ServiceSettings.CollapsedThreads = model.COLLAPSED_THREADS_DEFAULT_ON
})
userWSClient, err := th.CreateWebSocketClient()
require.Nil(t, err)
defer userWSClient.Close()
userWSClient.Listen()
Client := th.Client
rpost, resp := Client.CreatePost(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
CheckNoError(t, resp)
CheckCreatedStatus(t, resp)
_, err = th.App.CreatePostAsUser(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply", UserId: th.BasicUser2.Id, RootId: rpost.Id}, th.App.Session().Id, false)
require.Nil(t, err)
defer th.App.Srv().Store.Post().PermanentDeleteByUser(th.BasicUser.Id)
defer th.App.Srv().Store.Post().PermanentDeleteByUser(th.BasicUser2.Id)
t.Run("Listed for update event", func(t *testing.T) {
var caught bool
func() {
for {
select {
case ev := <-userWSClient.EventChannel:
if ev.EventType() == model.WEBSOCKET_EVENT_THREAD_UPDATED {
caught = true
thread, err := model.ThreadFromJson(ev.GetData()["thread"].(string))
require.Nil(t, err)
require.Contains(t, thread.Participants, th.BasicUser.Id)
require.Contains(t, thread.Participants, th.BasicUser2.Id)
}
case <-time.After(1 * time.Second):
return
}
}
}()
require.Truef(t, caught, "User should have received %s event", model.WEBSOCKET_EVENT_THREAD_UPDATED)
})
resp = th.Client.UpdateThreadFollowForUser(th.BasicUser.Id, rpost.Id, false)
CheckNoError(t, resp)
CheckOKStatus(t, resp)
t.Run("Listed for follow event", func(t *testing.T) {
var caught bool
func() {
for {
select {
case ev := <-userWSClient.EventChannel:
if ev.EventType() == model.WEBSOCKET_EVENT_THREAD_FOLLOW_CHANGED {
caught = true
require.Equal(t, ev.GetData()["state"], false)
}
case <-time.After(1 * time.Second):
return
}
}
}()
require.Truef(t, caught, "User should have received %s event", model.WEBSOCKET_EVENT_THREAD_FOLLOW_CHANGED)
})
resp = th.Client.UpdateThreadReadForUser(th.BasicUser.Id, rpost.Id, 123)
CheckNoError(t, resp)
CheckOKStatus(t, resp)
t.Run("Listed for read event", func(t *testing.T) {
var caught bool
func() {
for {
select {
case ev := <-userWSClient.EventChannel:
if ev.EventType() == model.WEBSOCKET_EVENT_THREAD_READ_CHANGED {
caught = true
require.EqualValues(t, ev.GetData()["timestamp"], 123)
}
case <-time.After(1 * time.Second):
return
}
}
}()
require.Truef(t, caught, "User should have received %s event", model.WEBSOCKET_EVENT_THREAD_READ_CHANGED)
})
}
func TestFollowThreads(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()