github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/user_terms_of_Service_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/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestUserTermsOfServiceIsValid(t *testing.T) { 15 s := UserTermsOfService{} 16 require.Error(t, s.IsValid(), "should be invalid") 17 18 s.UserId = NewId() 19 require.Error(t, s.IsValid(), "should be invalid") 20 21 s.TermsOfServiceId = NewId() 22 require.Error(t, s.IsValid(), "should be invalid") 23 24 s.CreateAt = GetMillis() 25 require.Nil(t, s.IsValid(), "should be valid") 26 } 27 28 func TestUserTermsOfServiceJson(t *testing.T) { 29 o := UserTermsOfService{ 30 UserId: NewId(), 31 TermsOfServiceId: NewId(), 32 CreateAt: GetMillis(), 33 } 34 j := o.ToJson() 35 ro := UserTermsOfServiceFromJson(strings.NewReader(j)) 36 37 assert.NotNil(t, ro) 38 assert.Equal(t, o, *ro) 39 }