MM-21481: Fixed several issues from user marshalling (#13627)

* MM-21481: Fixed several issues from user marshalling

- Fixed the root cause for panic by properly converting
the map to a User struct.
- Added a check for type conversion for extra safety.
- Fixed a somewhat unrelated issue of a pointer to pointer reference.

* Fix tests
Этот коммит содержится в:
Agniva De Sarker
2020-01-16 13:48:08 +05:30
коммит произвёл Claudio Costa
родитель 87eb7697f9
Коммит 2a28edcd93
5 изменённых файлов: 28 добавлений и 9 удалений

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

@@ -12,14 +12,20 @@ import (
)
func TestWebSocketEvent(t *testing.T) {
m := NewWebSocketEvent("some_event", NewId(), NewId(), NewId(), nil)
userId := NewId()
m := NewWebSocketEvent("some_event", NewId(), NewId(), userId, nil)
m.Add("RootId", NewId())
user := &User{
Id: userId,
}
m.Add("user", user)
json := m.ToJson()
result := WebSocketEventFromJson(strings.NewReader(json))
require.True(t, m.IsValid(), "should be valid")
require.Equal(t, m.GetBroadcast().TeamId, result.GetBroadcast().TeamId, "Ids do not match")
require.Equal(t, m.GetData()["RootId"], result.GetData()["RootId"], "Ids do not match")
require.Equal(t, m.GetBroadcast().TeamId, result.GetBroadcast().TeamId, "Team ids do not match")
require.Equal(t, m.GetData()["RootId"], result.GetData()["RootId"], "Root ids do not match")
require.Equal(t, m.GetData()["user"].(*User).Id, result.GetData()["user"].(*User).Id, "User ids do not match")
}
func TestWebSocketEventImmutable(t *testing.T) {