Files
mostlymatter/server/channels/api4/terms_of_service_test.go
Claudio Costa 611b2a8e79 [MM-62408] Server Code Coverage with Fully Parallel Tests (#30078)
* TestPool

* Store infra

* Store tests updates

* Bump maximum concurrent postgres connections

* More infra

* channels/jobs

* channels/app

* channels/api4

* Protect i18n from concurrent access

* Replace some use of os.Setenv

* Remove debug

* Lint fixes

* Fix more linting

* Fix test

* Remove use of Setenv in drafts tests

* Fix flaky TestWebHubCloseConnOnDBFail

* Fix merge

* [MM-62408] Add CI job to generate test coverage (#30284)

* Add CI job to generate test coverage

* Remove use of Setenv in drafts tests

* Fix flaky TestWebHubCloseConnOnDBFail

* Fix more Setenv usage

* Fix more potential flakyness

* Remove parallelism from flaky test

* Remove conflicting env var

* Fix

* Disable parallelism

* Test atomic covermode

* Disable parallelism

* Enable parallelism

* Add upload coverage step

* Fix codecov.yml

* Add codecov.yml

* Remove redundant workspace field

* Add Parallel() util methods and refactor

* Fix formatting

* More formatting fixes

* Fix reporting
2025-05-30 13:58:26 +02:00

63 строки
1.9 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
)
func TestGetTermsOfService(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t).InitBasic()
defer th.TearDown()
client := th.Client
_, appErr := th.App.CreateTermsOfService("abc", th.BasicUser.Id)
require.Nil(t, appErr)
termsOfService, _, err := client.GetTermsOfService(context.Background(), "")
require.NoError(t, err)
assert.NotNil(t, termsOfService)
assert.Equal(t, "abc", termsOfService.Text)
assert.NotEmpty(t, termsOfService.Id)
assert.NotEmpty(t, termsOfService.CreateAt)
}
func TestCreateTermsOfService(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t).InitBasic()
defer th.TearDown()
client := th.Client
_, _, err := client.CreateTermsOfService(context.Background(), "terms of service new", th.BasicUser.Id)
CheckErrorID(t, err, "api.context.permissions.app_error")
}
func TestCreateTermsOfServiceAdminUser(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t).InitBasic()
defer th.TearDown()
client := th.SystemAdminClient
termsOfService, _, err := client.CreateTermsOfService(context.Background(), "terms of service new", th.SystemAdminUser.Id)
CheckErrorID(t, err, "api.create_terms_of_service.custom_terms_of_service_disabled.app_error")
assert.Nil(t, termsOfService)
th.App.Srv().SetLicense(model.NewTestLicense("EnableCustomTermsOfService"))
termsOfService, _, err = client.CreateTermsOfService(context.Background(), "terms of service new_2", th.SystemAdminUser.Id)
require.NoError(t, err)
assert.NotEmpty(t, termsOfService.Id)
assert.NotEmpty(t, termsOfService.CreateAt)
assert.Equal(t, "terms of service new_2", termsOfService.Text)
assert.Equal(t, th.SystemAdminUser.Id, termsOfService.UserId)
}