github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/api4/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 api4
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  
    12  	"github.com/masterhung0112/hk_server/v5/model"
    13  )
    14  
    15  func TestGetTermsOfService(t *testing.T) {
    16  	th := Setup(t).InitBasic()
    17  	defer th.TearDown()
    18  	Client := th.Client
    19  
    20  	_, err := th.App.CreateTermsOfService("abc", th.BasicUser.Id)
    21  	require.Nil(t, err)
    22  
    23  	termsOfService, resp := Client.GetTermsOfService("")
    24  	CheckNoError(t, resp)
    25  
    26  	assert.NotNil(t, termsOfService)
    27  	assert.Equal(t, "abc", termsOfService.Text)
    28  	assert.NotEmpty(t, termsOfService.Id)
    29  	assert.NotEmpty(t, termsOfService.CreateAt)
    30  }
    31  
    32  func TestCreateTermsOfService(t *testing.T) {
    33  	th := Setup(t).InitBasic()
    34  	defer th.TearDown()
    35  	Client := th.Client
    36  
    37  	_, resp := Client.CreateTermsOfService("terms of service new", th.BasicUser.Id)
    38  	CheckErrorMessage(t, resp, "api.context.permissions.app_error")
    39  }
    40  
    41  func TestCreateTermsOfServiceAdminUser(t *testing.T) {
    42  	th := Setup(t).InitBasic()
    43  	defer th.TearDown()
    44  	Client := th.SystemAdminClient
    45  
    46  	termsOfService, resp := Client.CreateTermsOfService("terms of service new", th.SystemAdminUser.Id)
    47  	CheckErrorMessage(t, resp, "api.create_terms_of_service.custom_terms_of_service_disabled.app_error")
    48  	assert.Nil(t, termsOfService)
    49  
    50  	th.App.Srv().SetLicense(model.NewTestLicense("EnableCustomTermsOfService"))
    51  
    52  	termsOfService, resp = Client.CreateTermsOfService("terms of service new_2", th.SystemAdminUser.Id)
    53  	CheckNoError(t, resp)
    54  	assert.NotEmpty(t, termsOfService.Id)
    55  	assert.NotEmpty(t, termsOfService.CreateAt)
    56  	assert.Equal(t, "terms of service new_2", termsOfService.Text)
    57  	assert.Equal(t, th.SystemAdminUser.Id, termsOfService.UserId)
    58  }