Files
mattermost/model/terms_of_service_test.go
Harshil Sharma bffcccf99d Refactored to rename "service terms" to "terms of service" (#9581)
* #124 renamed identififers from service terms to terms of service

* #124 renamed identififers from service terms to terms of service

* 124 renamed ServiceTerms model to TermsOfService

* 124 Renamed EnableCustomServiceTerms feature flag to EnableCustomTermsOfService

* 124 Renamed EnableCustomServiceTerms feature flag to EnableCustomTermsOfService

* #124 fixed formatting

* #124 fixed formatting

* #132 renamed table ServiceTerms to TermsOfService

* #124 renamed some missed files from 'service_terms' to 'terms_of_service'

* #124 removed fixed TODOs

* drop migrate of ServiceTerms table, since backporting

* s/ServiceTerms/TermsOfService/ in tests

* s/AcceptedServiceTermsId/AcceptedTermsOfServiceId/

Change the model attribute, even though the column name will eventually be removed.

* s/accepted_service_terms_id/accepted_terms_of_service_id/ to match redux

* s/serviceTerms/termsOfService

* rename column too, and add max size constraint

* s/EnableCustomServiceTerms/EnableCustomTermsOfService
2018-10-09 20:55:47 -04:00

63 lines
1.2 KiB
Go

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
func TestTermsOfServiceIsValid(t *testing.T) {
s := TermsOfService{}
if err := s.IsValid(); err == nil {
t.Fatal("should be invalid")
}
s.Id = NewId()
if err := s.IsValid(); err == nil {
t.Fatal("should be invalid")
}
s.CreateAt = GetMillis()
if err := s.IsValid(); err == nil {
t.Fatal("should be invalid")
}
s.UserId = NewId()
if err := s.IsValid(); err != nil {
t.Fatal("should be invalid")
}
s.Text = strings.Repeat("0", POST_MESSAGE_MAX_RUNES_V2+1)
if err := s.IsValid(); err == nil {
t.Fatal("should be invalid")
}
s.Text = strings.Repeat("0", POST_MESSAGE_MAX_RUNES_V2)
if err := s.IsValid(); err != nil {
t.Fatal(err)
}
s.Text = "test"
if err := s.IsValid(); err != nil {
t.Fatal(err)
}
}
func TestTermsOfServiceJson(t *testing.T) {
o := TermsOfService{
Id: NewId(),
Text: NewId(),
CreateAt: GetMillis(),
UserId: NewId(),
}
j := o.ToJson()
ro := TermsOfServiceFromJson(strings.NewReader(j))
assert.NotNil(t, ro)
assert.Equal(t, o, *ro)
}