github.com/kongr45gpen/mattermost-server@v5.11.1+incompatible/model/user_terms_of_Service_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/assert"
    11  )
    12  
    13  func TestUserTermsOfServiceIsValid(t *testing.T) {
    14  	s := UserTermsOfService{}
    15  
    16  	if err := s.IsValid(); err == nil {
    17  		t.Fatal("should be invalid")
    18  	}
    19  
    20  	s.UserId = NewId()
    21  	if err := s.IsValid(); err == nil {
    22  		t.Fatal("should be invalid")
    23  	}
    24  
    25  	s.TermsOfServiceId = NewId()
    26  	if err := s.IsValid(); err == nil {
    27  		t.Fatal("should be invalid")
    28  	}
    29  
    30  	s.CreateAt = GetMillis()
    31  	if err := s.IsValid(); err != nil {
    32  		t.Fatal("should be valid")
    33  	}
    34  }
    35  
    36  func TestUserTermsOfServiceJson(t *testing.T) {
    37  	o := UserTermsOfService{
    38  		UserId:           NewId(),
    39  		TermsOfServiceId: NewId(),
    40  		CreateAt:         GetMillis(),
    41  	}
    42  	j := o.ToJson()
    43  	ro := UserTermsOfServiceFromJson(strings.NewReader(j))
    44  
    45  	assert.NotNil(t, ro)
    46  	assert.Equal(t, o, *ro)
    47  }