blob: cbc564b6ca7ddca3d0f4e11b739f82c6c5d9e6ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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")
}
}
|