// 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) }) }