Files
mostlymatter/server/channels/api4/scheduled_post_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

75 строки
2.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
import (
"context"
"testing"
"github.com/mattermost/mattermost/server/public/model"
"github.com/stretchr/testify/require"
)
func TestCreateScheduledPost(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
client := th.Client
t.Run("base case", func(t *testing.T) {
userId := model.NewId()
scheduledPost := &model.ScheduledPost{
Draft: model.Draft{
CreateAt: model.GetMillis(),
UserId: userId,
ChannelId: th.BasicChannel.Id,
Message: "this is a scheduled post",
},
ScheduledAt: model.GetMillis() + 100000, // 100 seconds in the future
}
createdScheduledPost, _, err := client.CreateScheduledPost(context.Background(), scheduledPost)
require.NoError(t, err)
require.NotNil(t, createdScheduledPost)
})
t.Run("should not allow created scheduled post in read-only channel", func(t *testing.T) {
channel := th.CreatePublicChannel()
th.AddUserToChannel(th.BasicUser, channel)
channelModerationPatches := []*model.ChannelModerationPatch{
{
Name: model.NewPointer(model.PermissionCreatePost.Id),
Roles: &model.ChannelModeratedRolesPatch{
Guests: model.NewPointer(true),
Members: model.NewPointer(false),
},
},
}
err := th.App.SetPhase2PermissionsMigrationStatus(true)
require.NoError(t, err)
_, appErr := th.App.PatchChannelModerationsForChannel(th.Context, channel, channelModerationPatches)
require.Nil(t, appErr)
scheduledPost := &model.ScheduledPost{
Draft: model.Draft{
CreateAt: model.GetMillis(),
UserId: th.BasicUser.Id,
ChannelId: channel.Id,
Message: "this is a scheduled post",
},
ScheduledAt: model.GetMillis() + 100000, // 100 seconds in the future
}
createdScheduledPost, _, httpErr := client.CreateScheduledPost(context.Background(), scheduledPost)
require.Error(t, httpErr)
require.Contains(t, httpErr.Error(), "You do not have the appropriate permissions.")
require.Nil(t, createdScheduledPost)
})
}