github.com/jlevesy/mattermost-server@v5.3.2-0.20181003190404-7468f35cb0c8+incompatible/model/reaction_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  
    11  func TestReactionIsValid(t *testing.T) {
    12  	reaction := Reaction{
    13  		UserId:    NewId(),
    14  		PostId:    NewId(),
    15  		EmojiName: "emoji",
    16  		CreateAt:  GetMillis(),
    17  	}
    18  
    19  	if err := reaction.IsValid(); err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	reaction.UserId = ""
    24  	if err := reaction.IsValid(); err == nil {
    25  		t.Fatal("user id should be invalid")
    26  	}
    27  
    28  	reaction.UserId = "1234garbage"
    29  	if err := reaction.IsValid(); err == nil {
    30  		t.Fatal("user id should be invalid")
    31  	}
    32  
    33  	reaction.UserId = NewId()
    34  	reaction.PostId = ""
    35  	if err := reaction.IsValid(); err == nil {
    36  		t.Fatal("post id should be invalid")
    37  	}
    38  
    39  	reaction.PostId = "1234garbage"
    40  	if err := reaction.IsValid(); err == nil {
    41  		t.Fatal("post id should be invalid")
    42  	}
    43  
    44  	reaction.PostId = NewId()
    45  	reaction.EmojiName = strings.Repeat("a", 64)
    46  	if err := reaction.IsValid(); err != nil {
    47  		t.Fatal(err)
    48  	}
    49  
    50  	reaction.EmojiName = "emoji-"
    51  	if err := reaction.IsValid(); err != nil {
    52  		t.Fatal(err)
    53  	}
    54  
    55  	reaction.EmojiName = "emoji_"
    56  	if err := reaction.IsValid(); err != nil {
    57  		t.Fatal(err)
    58  	}
    59  
    60  	reaction.EmojiName = "+1"
    61  	if err := reaction.IsValid(); err != nil {
    62  		t.Fatal(err)
    63  	}
    64  
    65  	reaction.EmojiName = "emoji:"
    66  	if err := reaction.IsValid(); err == nil {
    67  		t.Fatal(err)
    68  	}
    69  
    70  	reaction.EmojiName = ""
    71  	if err := reaction.IsValid(); err == nil {
    72  		t.Fatal("emoji name should be invalid")
    73  	}
    74  
    75  	reaction.EmojiName = strings.Repeat("a", 65)
    76  	if err := reaction.IsValid(); err == nil {
    77  		t.Fatal("emoji name should be invalid")
    78  	}
    79  
    80  	reaction.CreateAt = 0
    81  	if err := reaction.IsValid(); err == nil {
    82  		t.Fatal("create at should be invalid")
    83  	}
    84  }