github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/model/team_member_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "strings" 8 "testing" 9 ) 10 11 func TestTeamMemberJson(t *testing.T) { 12 o := TeamMember{TeamId: NewId(), UserId: NewId()} 13 json := o.ToJson() 14 ro := TeamMemberFromJson(strings.NewReader(json)) 15 16 if o.TeamId != ro.TeamId { 17 t.Fatal("Ids do not match") 18 } 19 } 20 21 func TestTeamMemberIsValid(t *testing.T) { 22 o := TeamMember{} 23 24 if err := o.IsValid(); err == nil { 25 t.Fatal("should be invalid") 26 } 27 28 o.TeamId = NewId() 29 if err := o.IsValid(); err == nil { 30 t.Fatal("should be invalid") 31 } 32 33 /*o.UserId = NewId() 34 o.Roles = "blahblah" 35 if err := o.IsValid(); err == nil { 36 t.Fatal("should be invalid") 37 } 38 39 o.Roles = "" 40 if err := o.IsValid(); err != nil { 41 t.Fatal(err) 42 }*/ 43 } 44 45 func TestUnreadMemberJson(t *testing.T) { 46 o := TeamUnread{TeamId: NewId(), MsgCount: 5, MentionCount: 3} 47 json := o.ToJson() 48 49 r := TeamUnreadFromJson(strings.NewReader(json)) 50 if o.TeamId != r.TeamId { 51 t.Fatal("Ids do not match") 52 } 53 54 if o.MsgCount != r.MsgCount { 55 t.Fatal("MsgCount do not match") 56 } 57 }