diff --git a/server/channels/api4/apitestlib.go b/server/channels/api4/apitestlib.go index 2588d12e93..5a6be838f4 100644 --- a/server/channels/api4/apitestlib.go +++ b/server/channels/api4/apitestlib.go @@ -555,6 +555,25 @@ func (th *TestHelper) CreateLocalClient(socketPath string) *model.Client4 { } } +func (th *TestHelper) CreateConnectedWebSocketClient(t *testing.T) *model.WebSocketClient { + t.Helper() + wsClient, err := th.CreateWebSocketClient() + require.NoError(t, err) + require.NotNil(t, wsClient, "webSocketClient should not be nil") + wsClient.Listen() + t.Cleanup(wsClient.Close) + + // Ensure WS is connected. First event should be hello message. + select { + case ev := <-wsClient.EventChannel: + require.Equal(t, model.WebsocketEventHello, ev.EventType()) + case <-time.After(5 * time.Second): + require.FailNow(t, "hello event was not received within the timeout period") + } + + return wsClient +} + func (th *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, error) { return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port), th.Client.AuthToken) } diff --git a/server/channels/api4/channel_bookmark_test.go b/server/channels/api4/channel_bookmark_test.go index c96e6d0024..8b3902a339 100644 --- a/server/channels/api4/channel_bookmark_test.go +++ b/server/channels/api4/channel_bookmark_test.go @@ -221,13 +221,7 @@ func TestCreateChannelBookmark(t *testing.T) { }) t.Run("a websockets event should be fired as part of creating a bookmark", func(t *testing.T) { - t.Skip("MM-62437") - - webSocketClient, err := th.CreateWebSocketClient() - require.NoError(t, err) - require.NotNil(t, webSocketClient, "webSocketClient should not be nil") - webSocketClient.Listen() - defer webSocketClient.Close() + webSocketClient := th.CreateConnectedWebSocketClient(t) bookmark1 := &model.ChannelBookmark{ ChannelId: th.BasicChannel.Id, @@ -242,7 +236,7 @@ func TestCreateChannelBookmark(t *testing.T) { th.Context.Session().UserId = th.BasicUser.Id defer func() { th.Context.Session().UserId = originalSessionUserId }() - _, appErr := th.App.CreateChannelBookmark(th.Context, bookmark1, "") + bookmark, appErr := th.App.CreateChannelBookmark(th.Context, bookmark1, "") require.Nil(t, appErr) var b model.ChannelBookmarkWithFileInfo @@ -266,6 +260,7 @@ func TestCreateChannelBookmark(t *testing.T) { require.True(t, eventReceived, "Expected WebSocket event was not received within the timeout period") require.NotNil(t, b) require.NotEmpty(t, b.Id) + require.Equal(t, bookmark, &b) }) } @@ -600,12 +595,7 @@ func TestEditChannelBookmark(t *testing.T) { }) t.Run("a websockets event should be fired as part of editing a bookmark", func(t *testing.T) { - t.Skip("https://mattermost.atlassian.net/browse/MM-61779") - webSocketClient, err := th.CreateWebSocketClient() - require.NoError(t, err) - require.NotNil(t, webSocketClient, "webSocketClient should not be nil") - webSocketClient.Listen() - defer webSocketClient.Close() + webSocketClient := th.CreateConnectedWebSocketClient(t) bookmark1 := &model.ChannelBookmark{ ChannelId: th.BasicChannel.Id, @@ -975,14 +965,9 @@ func TestUpdateChannelBookmarkSortOrder(t *testing.T) { }) t.Run("a websockets event should be fired as part of editing a bookmark's sort order", func(t *testing.T) { - t.Skip("MM-61301") now := model.GetMillis() - webSocketClient, err := th.CreateWebSocketClient() - require.NoError(t, err) - require.NotNil(t, webSocketClient, "webSocketClient should not be nil") - webSocketClient.Listen() - defer webSocketClient.Close() + webSocketClient := th.CreateConnectedWebSocketClient(t) bookmark := &model.ChannelBookmark{ ChannelId: th.BasicChannel.Id, @@ -1332,11 +1317,7 @@ func TestDeleteChannelBookmark(t *testing.T) { }) t.Run("a websockets event should be fired as part of deleting a bookmark", func(t *testing.T) { - webSocketClient, err := th.CreateWebSocketClient() - require.NoError(t, err) - require.NotNil(t, webSocketClient, "webSocketClient should not be nil") - webSocketClient.Listen() - defer webSocketClient.Close() + webSocketClient := th.CreateConnectedWebSocketClient(t) bookmark := &model.ChannelBookmark{ ChannelId: th.BasicChannel.Id,