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 /model/websocket_message_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 'model/websocket_message_test.go')
-rw-r--r-- | model/websocket_message_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/model/websocket_message_test.go b/model/websocket_message_test.go new file mode 100644 index 000000000..cbc564b6c --- /dev/null +++ b/model/websocket_message_test.go @@ -0,0 +1,56 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" + "testing" +) + +func TestWebSocketEvent(t *testing.T) { + m := NewWebSocketEvent(NewId(), NewId(), NewId(), "some_event") + m.Add("RootId", NewId()) + json := m.ToJson() + result := WebSocketEventFromJson(strings.NewReader(json)) + + badresult := WebSocketEventFromJson(strings.NewReader("junk")) + if badresult != nil { + t.Fatal("should not have parsed") + } + + if !m.IsValid() { + t.Fatal("should be valid") + } + + if m.TeamId != result.TeamId { + t.Fatal("Ids do not match") + } + + if m.Data["RootId"] != result.Data["RootId"] { + t.Fatal("Ids do not match") + } +} + +func TestWebSocketResponse(t *testing.T) { + m := NewWebSocketResponse("OK", 1, map[string]interface{}{}) + e := NewWebSocketError(1, &AppError{}) + m.Add("RootId", NewId()) + json := m.ToJson() + result := WebSocketResponseFromJson(strings.NewReader(json)) + json2 := e.ToJson() + WebSocketResponseFromJson(strings.NewReader(json2)) + + badresult := WebSocketResponseFromJson(strings.NewReader("junk")) + if badresult != nil { + t.Fatal("should not have parsed") + } + + if !m.IsValid() { + t.Fatal("should be valid") + } + + if m.Data["RootId"] != result.Data["RootId"] { + t.Fatal("Ids do not match") + } +} |