* 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
74 строки
2.1 KiB
Go
74 строки
2.1 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) {
|
|
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)
|
|
})
|
|
}
|