github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/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  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestChannelMemberJson(t *testing.T) {
    14  	o := ChannelMember{ChannelId: NewId(), UserId: NewId()}
    15  	json := o.ToJson()
    16  	ro := ChannelMemberFromJson(strings.NewReader(json))
    17  
    18  	require.Equal(t, o.ChannelId, ro.ChannelId, "ids do not match")
    19  }
    20  
    21  func TestChannelMemberIsValid(t *testing.T) {
    22  	o := ChannelMember{}
    23  
    24  	require.Error(t, o.IsValid(), "should be invalid")
    25  
    26  	o.ChannelId = NewId()
    27  	require.Error(t, o.IsValid(), "should be invalid")
    28  
    29  	o.NotifyProps = GetDefaultChannelNotifyProps()
    30  	o.UserId = NewId()
    31  
    32  	o.NotifyProps["desktop"] = "junk"
    33  	require.Error(t, o.IsValid(), "should be invalid")
    34  
    35  	o.NotifyProps["desktop"] = "123456789012345678901"
    36  	require.Error(t, o.IsValid(), "should be invalid")
    37  
    38  	o.NotifyProps["desktop"] = CHANNEL_NOTIFY_ALL
    39  	require.Error(t, o.IsValid(), "should be invalid")
    40  
    41  	o.NotifyProps["mark_unread"] = "123456789012345678901"
    42  	require.Error(t, o.IsValid(), "should be invalid")
    43  
    44  	o.NotifyProps["mark_unread"] = CHANNEL_MARK_UNREAD_ALL
    45  	require.Error(t, o.IsValid(), "should be invalid")
    46  
    47  	o.Roles = ""
    48  	require.Error(t, o.IsValid(), "should be invalid")
    49  }
    50  
    51  func TestChannelUnreadJson(t *testing.T) {
    52  	o := ChannelUnread{ChannelId: NewId(), TeamId: NewId(), MsgCount: 5, MentionCount: 3}
    53  	json := o.ToJson()
    54  	ro := ChannelUnreadFromJson(strings.NewReader(json))
    55  
    56  	require.Equal(t, o.TeamId, ro.TeamId, "team Ids do not match")
    57  	require.Equal(t, o.MentionCount, ro.MentionCount, "mention count do not match")
    58  }