Scheudled post test enhancement (#29187)
* Added test for user beloonging to channel but not team * Added test for read onmly channel * Added test for fetching scheduled posts for team you don;'t belong to * Added more tests * test enhancements * CI
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
56260e93d4
Коммит
7c3d71c089
73
server/channels/api4/scheduled_post_test.go
Обычный файл
73
server/channels/api4/scheduled_post_test.go
Обычный файл
@@ -0,0 +1,73 @@
|
||||
// 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) {
|
||||
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)
|
||||
})
|
||||
}
|
||||
Ссылка в новой задаче
Block a user