github.com/rajatvaryani/mattermost-server@v5.11.1+incompatible/api4/terms_of_service_test.go (about)

     1  package api4
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mattermost/mattermost-server/model"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestGetTermsOfService(t *testing.T) {
    11  	th := Setup().InitBasic()
    12  	defer th.TearDown()
    13  	Client := th.Client
    14  
    15  	_, err := th.App.CreateTermsOfService("abc", th.BasicUser.Id)
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  
    20  	termsOfService, resp := Client.GetTermsOfService("")
    21  	CheckNoError(t, resp)
    22  
    23  	assert.NotNil(t, termsOfService)
    24  	assert.Equal(t, "abc", termsOfService.Text)
    25  	assert.NotEmpty(t, termsOfService.Id)
    26  	assert.NotEmpty(t, termsOfService.CreateAt)
    27  }
    28  
    29  func TestCreateTermsOfService(t *testing.T) {
    30  	th := Setup().InitBasic()
    31  	defer th.TearDown()
    32  	Client := th.Client
    33  
    34  	_, resp := Client.CreateTermsOfService("terms of service new", th.BasicUser.Id)
    35  	CheckErrorMessage(t, resp, "api.context.permissions.app_error")
    36  }
    37  
    38  func TestCreateTermsOfServiceAdminUser(t *testing.T) {
    39  	th := Setup().InitBasic()
    40  	defer th.TearDown()
    41  	Client := th.SystemAdminClient
    42  
    43  	termsOfService, resp := Client.CreateTermsOfService("terms of service new", th.SystemAdminUser.Id)
    44  	CheckErrorMessage(t, resp, "api.create_terms_of_service.custom_terms_of_service_disabled.app_error")
    45  
    46  	th.App.SetLicense(model.NewTestLicense("EnableCustomTermsOfService"))
    47  
    48  	termsOfService, resp = Client.CreateTermsOfService("terms of service new_2", th.SystemAdminUser.Id)
    49  	CheckNoError(t, resp)
    50  	assert.NotEmpty(t, termsOfService.Id)
    51  	assert.NotEmpty(t, termsOfService.CreateAt)
    52  	assert.Equal(t, "terms of service new_2", termsOfService.Text)
    53  	assert.Equal(t, th.SystemAdminUser.Id, termsOfService.UserId)
    54  }