summaryrefslogtreecommitdiffstats
path: root/model/team_member_test.go
blob: 3661fff4b740d45f0a30da704d70342a5fa95980 (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
57
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package model

import (
	"strings"
	"testing"
)

func TestTeamMemberJson(t *testing.T) {
	o := TeamMember{TeamId: NewId(), UserId: NewId()}
	json := o.ToJson()
	ro := TeamMemberFromJson(strings.NewReader(json))

	if o.TeamId != ro.TeamId {
		t.Fatal("Ids do not match")
	}
}

func TestTeamMemberIsValid(t *testing.T) {
	o := TeamMember{}

	if err := o.IsValid(); err == nil {
		t.Fatal("should be invalid")
	}

	o.TeamId = NewId()
	if err := o.IsValid(); err == nil {
		t.Fatal("should be invalid")
	}

	/*o.UserId = NewId()
	o.Roles = "blahblah"
	if err := o.IsValid(); err == nil {
		t.Fatal("should be invalid")
	}

	o.Roles = ""
	if err := o.IsValid(); err != nil {
		t.Fatal(err)
	}*/
}

func TestUnreadMemberJson(t *testing.T) {
	o := TeamUnread{TeamId: NewId(), MsgCount: 5, MentionCount: 3}
	json := o.ToJson()

	r := TeamUnreadFromJson(strings.NewReader(json))
	if o.TeamId != r.TeamId {
		t.Fatal("Ids do not match")
	}

	if o.MsgCount != r.MsgCount {
		t.Fatal("MsgCount do not match")
	}
}