Added infrastructure for basic WebSocket API (#3432)

Этот коммит содержится в:
Joram Wilander
2016-07-12 09:36:27 -04:00
коммит произвёл GitHub
родитель 06eacf30b9
Коммит ad343a0f4a
32 изменённых файлов: 820 добавлений и 363 удалений

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

@@ -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")
}
}