diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-07-12 09:36:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-12 09:36:27 -0400 |
commit | ad343a0f4ad175053f7d0da12a0587bcbb396d1c (patch) | |
tree | 8e1be00202a1d3a037ec75879538eb0ba1f25c01 /api/user_test.go | |
parent | 06eacf30b97aacf6544552448635b7f078d2c90b (diff) | |
download | chat-ad343a0f4ad175053f7d0da12a0587bcbb396d1c.tar.gz chat-ad343a0f4ad175053f7d0da12a0587bcbb396d1c.tar.bz2 chat-ad343a0f4ad175053f7d0da12a0587bcbb396d1c.zip |
Added infrastructure for basic WebSocket API (#3432)
Diffstat (limited to 'api/user_test.go')
-rw-r--r-- | api/user_test.go | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/api/user_test.go b/api/user_test.go index 7dabc8e9b..12390135e 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -1719,3 +1719,85 @@ func TestCheckMfa(t *testing.T) { // need to add more test cases when enterprise bits can be loaded into tests } + +func TestUserTyping(t *testing.T) { + th := Setup().InitBasic() + Client := th.BasicClient + WebSocketClient, err := th.CreateWebSocketClient() + if err != nil { + t.Fatal(err) + } + defer WebSocketClient.Close() + WebSocketClient.Listen() + + WebSocketClient.UserTyping("", "") + time.Sleep(300 * time.Millisecond) + if resp := <-WebSocketClient.ResponseChannel; resp.Error.Id != "api.websocket_handler.invalid_param.app_error" { + t.Fatal("should have been invalid param response") + } + + th.LoginBasic2() + Client.Must(Client.JoinChannel(th.BasicChannel.Id)) + + WebSocketClient2, err2 := th.CreateWebSocketClient() + if err2 != nil { + t.Fatal(err2) + } + defer WebSocketClient2.Close() + WebSocketClient2.Listen() + + WebSocketClient.UserTyping(th.BasicChannel.Id, "") + + time.Sleep(300 * time.Millisecond) + + stop := make(chan bool) + eventHit := false + + go func() { + for { + select { + case resp := <-WebSocketClient2.EventChannel: + if resp.Event == model.WEBSOCKET_EVENT_TYPING && resp.UserId == th.BasicUser.Id { + eventHit = true + } + case <-stop: + return + } + } + }() + + time.Sleep(300 * time.Millisecond) + + stop <- true + + if !eventHit { + t.Fatal("did not receive typing event") + } + + WebSocketClient.UserTyping(th.BasicChannel.Id, "someparentid") + + time.Sleep(300 * time.Millisecond) + + eventHit = false + + go func() { + for { + select { + case resp := <-WebSocketClient2.EventChannel: + if resp.Event == model.WEBSOCKET_EVENT_TYPING && resp.Data["parent_id"] == "someparentid" { + eventHit = true + } + case <-stop: + return + } + } + }() + + time.Sleep(300 * time.Millisecond) + + stop <- true + + if !eventHit { + t.Fatal("did not receive typing event") + } +} |