summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2018-05-28 22:31:08 +0800
committerGitHub <noreply@github.com>2018-05-28 22:31:08 +0800
commitc37d153ffb276e501660133de836a61eec25e544 (patch)
tree6c45576f1df735922aecd5d7e29458f945e46dba /api4
parentc3e9c414408a8c9c2806af12e659e395c605496f (diff)
downloadchat-c37d153ffb276e501660133de836a61eec25e544.tar.gz
chat-c37d153ffb276e501660133de836a61eec25e544.tar.bz2
chat-c37d153ffb276e501660133de836a61eec25e544.zip
[MM-10519] Send websocket event whenever the channel has changed it's type (public|private) (#8798)
* send websocket event whenever the channel has changed it's type (public|private) * updated per comment Signed-off-by: Saturnino Abril <saturnino.abril@gmail.com> * add channel_converted websocket event Signed-off-by: Saturnino Abril <saturnino.abril@gmail.com> * only send channel_id via websocket message for "channel_converted" event Signed-off-by: Saturnino Abril <saturnino.abril@gmail.com>
Diffstat (limited to 'api4')
-rw-r--r--api4/channel_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/api4/channel_test.go b/api4/channel_test.go
index b428a382a..2a1e78753 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"testing"
+ "time"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
@@ -933,12 +934,42 @@ func TestConvertChannelToPrivate(t *testing.T) {
t.Fatal("should not return a channel")
}
+ WebSocketClient, err := th.CreateWebSocketClient()
+ if err != nil {
+ t.Fatal(err)
+ }
+ WebSocketClient.Listen()
+
publicChannel2 := th.CreatePublicChannel()
rchannel, resp = th.SystemAdminClient.ConvertChannelToPrivate(publicChannel2.Id)
CheckOKStatus(t, resp)
if rchannel.Type != model.CHANNEL_PRIVATE {
t.Fatal("channel should be converted from public to private")
}
+
+ stop := make(chan bool)
+ eventHit := false
+
+ go func() {
+ for {
+ select {
+ case resp := <-WebSocketClient.EventChannel:
+ if resp.Event == model.WEBSOCKET_EVENT_CHANNEL_CONVERTED && resp.Data["channel_id"].(string) == publicChannel2.Id {
+ eventHit = true
+ }
+ case <-stop:
+ return
+ }
+ }
+ }()
+
+ time.Sleep(400 * time.Millisecond)
+
+ stop <- true
+
+ if !eventHit {
+ t.Fatal("did not receive channel_converted event")
+ }
}
func TestRestoreChannel(t *testing.T) {