github.com/cjdelisle/matterfoss@v5.11.1+incompatible/model/emoji_test.go (about)

     1  // Copyright (c) 2016-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 TestEmojiIsValid(t *testing.T) {
    14  	emoji := Emoji{
    15  		Id:        NewId(),
    16  		CreateAt:  1234,
    17  		UpdateAt:  1234,
    18  		DeleteAt:  0,
    19  		CreatorId: NewId(),
    20  		Name:      "name",
    21  	}
    22  
    23  	if err := emoji.IsValid(); err != nil {
    24  		t.Fatal(err)
    25  	}
    26  
    27  	emoji.Id = "1234"
    28  	require.NotNil(t, emoji.IsValid())
    29  
    30  	emoji.Id = NewId()
    31  	emoji.CreateAt = 0
    32  	require.NotNil(t, emoji.IsValid())
    33  
    34  	emoji.CreateAt = 1234
    35  	emoji.UpdateAt = 0
    36  	require.NotNil(t, emoji.IsValid())
    37  
    38  	emoji.UpdateAt = 1234
    39  	emoji.CreatorId = strings.Repeat("1", 27)
    40  	require.NotNil(t, emoji.IsValid())
    41  
    42  	emoji.CreatorId = NewId()
    43  	emoji.Name = strings.Repeat("1", 65)
    44  	require.NotNil(t, emoji.IsValid())
    45  
    46  	emoji.Name = ""
    47  	require.NotNil(t, emoji.IsValid())
    48  
    49  	emoji.Name = strings.Repeat("1", 64)
    50  	require.Nil(t, emoji.IsValid())
    51  
    52  	emoji.Name = "name-"
    53  	require.Nil(t, emoji.IsValid())
    54  
    55  	emoji.Name = "name_"
    56  	require.Nil(t, emoji.IsValid())
    57  
    58  	emoji.Name = "name:"
    59  	require.NotNil(t, emoji.IsValid())
    60  
    61  	emoji.Name = "croissant"
    62  	require.NotNil(t, emoji.IsValid())
    63  }