github.com/pafomin-at-avito/mattermost-server@v5.11.1+incompatible/model/channel_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 TestChannelMemberJson(t *testing.T) {
    12  	o := ChannelMember{ChannelId: NewId(), UserId: NewId()}
    13  	json := o.ToJson()
    14  	ro := ChannelMemberFromJson(strings.NewReader(json))
    15  
    16  	if o.ChannelId != ro.ChannelId {
    17  		t.Fatal("Ids do not match")
    18  	}
    19  }
    20  
    21  func TestChannelMemberIsValid(t *testing.T) {
    22  	o := ChannelMember{}
    23  
    24  	if err := o.IsValid(); err == nil {
    25  		t.Fatal("should be invalid")
    26  	}
    27  
    28  	o.ChannelId = NewId()
    29  	if err := o.IsValid(); err == nil {
    30  		t.Fatal("should be invalid")
    31  	}
    32  
    33  	o.NotifyProps = GetDefaultChannelNotifyProps()
    34  	o.UserId = NewId()
    35  	/*o.Roles = "missing"
    36  	o.NotifyProps = GetDefaultChannelNotifyProps()
    37  	o.UserId = NewId()
    38  	if err := o.IsValid(); err == nil {
    39  		t.Fatal("should be invalid")
    40  	}*/
    41  
    42  	o.NotifyProps["desktop"] = "junk"
    43  	if err := o.IsValid(); err == nil {
    44  		t.Fatal("should be invalid")
    45  	}
    46  
    47  	o.NotifyProps["desktop"] = "123456789012345678901"
    48  	if err := o.IsValid(); err == nil {
    49  		t.Fatal("should be invalid")
    50  	}
    51  
    52  	o.NotifyProps["desktop"] = CHANNEL_NOTIFY_ALL
    53  	if err := o.IsValid(); err != nil {
    54  		t.Fatal(err)
    55  	}
    56  
    57  	o.NotifyProps["mark_unread"] = "123456789012345678901"
    58  	if err := o.IsValid(); err == nil {
    59  		t.Fatal("should be invalid")
    60  	}
    61  
    62  	o.NotifyProps["mark_unread"] = CHANNEL_MARK_UNREAD_ALL
    63  	if err := o.IsValid(); err != nil {
    64  		t.Fatal(err)
    65  	}
    66  
    67  	o.Roles = ""
    68  	if err := o.IsValid(); err != nil {
    69  		t.Fatal(err)
    70  	}
    71  }
    72  
    73  func TestChannelUnreadJson(t *testing.T) {
    74  	o := ChannelUnread{ChannelId: NewId(), TeamId: NewId(), MsgCount: 5, MentionCount: 3}
    75  	json := o.ToJson()
    76  	ro := ChannelUnreadFromJson(strings.NewReader(json))
    77  
    78  	if o.TeamId != ro.TeamId {
    79  		t.Fatal("Team Ids do not match")
    80  	}
    81  
    82  	if o.MentionCount != ro.MentionCount {
    83  		t.Fatal("MentionCount do not match")
    84  	}
    85  }