github.com/vnforks/kid@v5.11.1+incompatible/model/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 TestTermsOfServiceIsValid(t *testing.T) { 14 s := TermsOfService{} 15 16 if err := s.IsValid(); err == nil { 17 t.Fatal("should be invalid") 18 } 19 20 s.Id = NewId() 21 if err := s.IsValid(); err == nil { 22 t.Fatal("should be invalid") 23 } 24 25 s.CreateAt = GetMillis() 26 if err := s.IsValid(); err == nil { 27 t.Fatal("should be invalid") 28 } 29 30 s.UserId = NewId() 31 if err := s.IsValid(); err != nil { 32 t.Fatal("should be invalid") 33 } 34 35 s.Text = strings.Repeat("0", POST_MESSAGE_MAX_RUNES_V2+1) 36 if err := s.IsValid(); err == nil { 37 t.Fatal("should be invalid") 38 } 39 40 s.Text = strings.Repeat("0", POST_MESSAGE_MAX_RUNES_V2) 41 if err := s.IsValid(); err != nil { 42 t.Fatal(err) 43 } 44 45 s.Text = "test" 46 if err := s.IsValid(); err != nil { 47 t.Fatal(err) 48 } 49 } 50 51 func TestTermsOfServiceJson(t *testing.T) { 52 o := TermsOfService{ 53 Id: NewId(), 54 Text: NewId(), 55 CreateAt: GetMillis(), 56 UserId: NewId(), 57 } 58 j := o.ToJson() 59 ro := TermsOfServiceFromJson(strings.NewReader(j)) 60 61 assert.NotNil(t, ro) 62 assert.Equal(t, o, *ro) 63 }