Migrate to stateless app.App (#17542)
* add request context * move initialialization to server * use app interface instead of global app functions * remove app context from webconn * cleanup * remove duplicated services * move context to separate package * remove finalize init method and move content to NewServer function * restart workers and schedulers after adding license for tests * reflect review comments Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c09369f14a
Коммит
5ea06e51d0
272
app/post_test.go
272
app/post_test.go
@@ -31,7 +31,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
|
||||
t.Run("duplicate create post is idempotent", func(t *testing.T) {
|
||||
pendingPostId := model.NewId()
|
||||
post, err := th.App.CreatePostAsUser(&model.Post{
|
||||
post, err := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
@@ -40,7 +40,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "message", post.Message)
|
||||
|
||||
duplicatePost, err := th.App.CreatePostAsUser(&model.Post{
|
||||
duplicatePost, err := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
@@ -77,10 +77,10 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
`, `{"id": "testrejectfirstpost", "backend": {"executable": "backend.exe"}}`, "testrejectfirstpost", th.App)
|
||||
`, `{"id": "testrejectfirstpost", "backend": {"executable": "backend.exe"}}`, "testrejectfirstpost", th.App, th.Context)
|
||||
|
||||
pendingPostId := model.NewId()
|
||||
post, err := th.App.CreatePostAsUser(&model.Post{
|
||||
post, err := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
@@ -90,7 +90,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
require.Equal(t, "Post rejected by plugin. rejected", err.Id)
|
||||
require.Nil(t, post)
|
||||
|
||||
duplicatePost, err := th.App.CreatePostAsUser(&model.Post{
|
||||
duplicatePost, err := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
@@ -127,7 +127,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
`, `{"id": "testdelayfirstpost", "backend": {"executable": "backend.exe"}}`, "testdelayfirstpost", th.App)
|
||||
`, `{"id": "testdelayfirstpost", "backend": {"executable": "backend.exe"}}`, "testdelayfirstpost", th.App, th.Context)
|
||||
|
||||
var post *model.Post
|
||||
pendingPostId := model.NewId()
|
||||
@@ -140,7 +140,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
var appErr *model.AppError
|
||||
post, appErr = th.App.CreatePostAsUser(&model.Post{
|
||||
post, appErr = th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "plugin delayed",
|
||||
@@ -154,7 +154,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// Try creating a duplicate post
|
||||
duplicatePost, err := th.App.CreatePostAsUser(&model.Post{
|
||||
duplicatePost, err := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "plugin delayed",
|
||||
@@ -170,7 +170,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
|
||||
t.Run("duplicate create post after cache expires is not idempotent", func(t *testing.T) {
|
||||
pendingPostId := model.NewId()
|
||||
post, err := th.App.CreatePostAsUser(&model.Post{
|
||||
post, err := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
@@ -181,7 +181,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
|
||||
|
||||
time.Sleep(PendingPostIDsCacheTTL)
|
||||
|
||||
duplicatePost, err := th.App.CreatePostAsUser(&model.Post{
|
||||
duplicatePost, err := th.App.CreatePostAsUser(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
@@ -263,7 +263,7 @@ func TestUpdatePostEditAt(t *testing.T) {
|
||||
post := th.BasicPost.Clone()
|
||||
|
||||
post.IsPinned = true
|
||||
saved, err := th.App.UpdatePost(post, true)
|
||||
saved, err := th.App.UpdatePost(th.Context, post, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, saved.EditAt, post.EditAt, "shouldn't have updated post.EditAt when pinning post")
|
||||
post = saved.Clone()
|
||||
@@ -271,7 +271,7 @@ func TestUpdatePostEditAt(t *testing.T) {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
||||
post.Message = model.NewId()
|
||||
saved, err = th.App.UpdatePost(post, true)
|
||||
saved, err = th.App.UpdatePost(th.Context, post, true)
|
||||
require.Nil(t, err)
|
||||
assert.NotEqual(t, saved.EditAt, post.EditAt, "should have updated post.EditAt when updating post message")
|
||||
|
||||
@@ -289,7 +289,7 @@ func TestUpdatePostTimeLimit(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.PostEditTimeLimit = -1
|
||||
})
|
||||
_, err := th.App.UpdatePost(post, true)
|
||||
_, err := th.App.UpdatePost(th.Context, post, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
@@ -297,14 +297,14 @@ func TestUpdatePostTimeLimit(t *testing.T) {
|
||||
})
|
||||
post.Message = model.NewId()
|
||||
|
||||
_, err = th.App.UpdatePost(post, true)
|
||||
_, err = th.App.UpdatePost(th.Context, post, true)
|
||||
require.Nil(t, err, "should allow you to edit the post")
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.PostEditTimeLimit = 1
|
||||
})
|
||||
post.Message = model.NewId()
|
||||
_, err = th.App.UpdatePost(post, true)
|
||||
_, err = th.App.UpdatePost(th.Context, post, true)
|
||||
require.NotNil(t, err, "should fail on update old post")
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
@@ -318,9 +318,9 @@ func TestUpdatePostInArchivedChannel(t *testing.T) {
|
||||
|
||||
archivedChannel := th.CreateChannel(th.BasicTeam)
|
||||
post := th.CreatePost(archivedChannel)
|
||||
th.App.DeleteChannel(archivedChannel, "")
|
||||
th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
|
||||
_, err := th.App.UpdatePost(post, true)
|
||||
_, err := th.App.UpdatePost(th.Context, post, true)
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "api.post.update_post.can_not_update_post_in_deleted.error", err.Id)
|
||||
}
|
||||
@@ -339,7 +339,7 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
||||
_, err := th.App.AddUserToChannel(userInChannel, channel, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = th.App.RemoveUserFromChannel(userNotInChannel.Id, "", channel)
|
||||
err = th.App.RemoveUserFromChannel(th.Context, userNotInChannel.Id, "", channel)
|
||||
require.Nil(t, err)
|
||||
replyPost := model.Post{
|
||||
Message: "asd",
|
||||
@@ -351,7 +351,7 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
_, err = th.App.CreatePostAsUser(&replyPost, "", true)
|
||||
_, err = th.App.CreatePostAsUser(th.Context, &replyPost, "", true)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ func TestPostAttachPostToChildPost(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
res1, err := th.App.CreatePostAsUser(&replyPost1, "", true)
|
||||
res1, err := th.App.CreatePostAsUser(th.Context, &replyPost1, "", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
replyPost2 := model.Post{
|
||||
@@ -386,7 +386,7 @@ func TestPostAttachPostToChildPost(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
_, err = th.App.CreatePostAsUser(&replyPost2, "", true)
|
||||
_, err = th.App.CreatePostAsUser(th.Context, &replyPost2, "", true)
|
||||
assert.Equalf(t, err.StatusCode, http.StatusBadRequest, "Expected BadRequest error, got %v", err)
|
||||
|
||||
replyPost3 := model.Post{
|
||||
@@ -399,7 +399,7 @@ func TestPostAttachPostToChildPost(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
_, err = th.App.CreatePostAsUser(&replyPost3, "", true)
|
||||
_, err = th.App.CreatePostAsUser(th.Context, &replyPost3, "", true)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ func TestPostChannelMentions(t *testing.T) {
|
||||
channel := th.BasicChannel
|
||||
user := th.BasicUser
|
||||
|
||||
channelToMention, err := th.App.CreateChannel(&model.Channel{
|
||||
channelToMention, err := th.App.CreateChannel(th.Context, &model.Channel{
|
||||
DisplayName: "Mention Test",
|
||||
Name: "mention-test",
|
||||
Type: model.CHANNEL_OPEN,
|
||||
@@ -430,7 +430,7 @@ func TestPostChannelMentions(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
result, err := th.App.CreatePostAsUser(post, "", true)
|
||||
result, err := th.App.CreatePostAsUser(th.Context, post, "", true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"mention-test": map[string]interface{}{
|
||||
@@ -440,7 +440,7 @@ func TestPostChannelMentions(t *testing.T) {
|
||||
}, result.GetProp("channel_mentions"))
|
||||
|
||||
post.Message = fmt.Sprintf("goodbye, ~%v!", channelToMention.Name)
|
||||
result, err = th.App.UpdatePost(post, false)
|
||||
result, err = th.App.UpdatePost(th.Context, post, false)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"mention-test": map[string]interface{}{
|
||||
@@ -630,7 +630,7 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
|
||||
filename := "test"
|
||||
data := []byte("abcd")
|
||||
|
||||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
|
||||
info1, err := th.App.DoUploadFile(th.Context, time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
||||
@@ -646,7 +646,7 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
|
||||
FileIds: []string{info1.Id},
|
||||
}
|
||||
|
||||
post, err = th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
post, err = th.App.CreatePost(th.Context, post, th.BasicChannel, false, true)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Delete the post.
|
||||
@@ -667,7 +667,7 @@ func TestDeletePostInArchivedChannel(t *testing.T) {
|
||||
|
||||
archivedChannel := th.CreateChannel(th.BasicTeam)
|
||||
post := th.CreatePost(archivedChannel)
|
||||
th.App.DeleteChannel(archivedChannel, "")
|
||||
th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
|
||||
_, err := th.App.DeletePost(post.Id, "")
|
||||
require.NotNil(t, err)
|
||||
@@ -698,7 +698,7 @@ func TestCreatePost(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
rpost, err := th.App.CreatePost(th.Context, post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "", rpost.Message)
|
||||
})
|
||||
@@ -714,7 +714,7 @@ func TestCreatePost(t *testing.T) {
|
||||
Message: "This post does not have mentions",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
rpost, err := th.App.CreatePost(postWithNoMention, th.BasicChannel, false, true)
|
||||
rpost, err := th.App.CreatePost(th.Context, postWithNoMention, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProps(), model.StringInterface{})
|
||||
|
||||
@@ -723,7 +723,7 @@ func TestCreatePost(t *testing.T) {
|
||||
Message: "This post has @here mention @all",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
rpost, err = th.App.CreatePost(postWithMention, th.BasicChannel, false, true)
|
||||
rpost, err = th.App.CreatePost(th.Context, postWithMention, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProps(), model.StringInterface{})
|
||||
})
|
||||
@@ -737,7 +737,7 @@ func TestCreatePost(t *testing.T) {
|
||||
Message: "This post does not have mentions",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
rpost, err := th.App.CreatePost(postWithNoMention, th.BasicChannel, false, true)
|
||||
rpost, err := th.App.CreatePost(th.Context, postWithNoMention, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProps(), model.StringInterface{})
|
||||
|
||||
@@ -746,7 +746,7 @@ func TestCreatePost(t *testing.T) {
|
||||
Message: "This post has @here mention @all",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
rpost, err = th.App.CreatePost(postWithMention, th.BasicChannel, false, true)
|
||||
rpost, err = th.App.CreatePost(th.Context, postWithMention, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProp(model.POST_PROPS_MENTION_HIGHLIGHT_DISABLED), true)
|
||||
|
||||
@@ -780,7 +780,7 @@ func TestPatchPost(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
rpost, err := th.App.CreatePost(th.Context, post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.NotEqual(t, "", rpost.Message)
|
||||
|
||||
@@ -788,7 +788,7 @@ func TestPatchPost(t *testing.T) {
|
||||
Message: model.NewString(""),
|
||||
}
|
||||
|
||||
rpost, err = th.App.PatchPost(rpost.Id, patch)
|
||||
rpost, err = th.App.PatchPost(th.Context, rpost.Id, patch)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "", rpost.Message)
|
||||
})
|
||||
@@ -805,19 +805,19 @@ func TestPatchPost(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
rpost, err := th.App.CreatePost(th.Context, post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("Does not set prop when user has USE_CHANNEL_MENTIONS", func(t *testing.T) {
|
||||
patchWithNoMention := &model.PostPatch{Message: model.NewString("This patch has no channel mention")}
|
||||
|
||||
rpost, err = th.App.PatchPost(rpost.Id, patchWithNoMention)
|
||||
rpost, err = th.App.PatchPost(th.Context, rpost.Id, patchWithNoMention)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProps(), model.StringInterface{})
|
||||
|
||||
patchWithMention := &model.PostPatch{Message: model.NewString("This patch has a mention now @here")}
|
||||
|
||||
rpost, err = th.App.PatchPost(rpost.Id, patchWithMention)
|
||||
rpost, err = th.App.PatchPost(th.Context, rpost.Id, patchWithMention)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProps(), model.StringInterface{})
|
||||
})
|
||||
@@ -827,13 +827,13 @@ func TestPatchPost(t *testing.T) {
|
||||
th.RemovePermissionFromRole(model.PERMISSION_USE_CHANNEL_MENTIONS.Id, model.CHANNEL_ADMIN_ROLE_ID)
|
||||
|
||||
patchWithNoMention := &model.PostPatch{Message: model.NewString("This patch still does not have a mention")}
|
||||
rpost, err = th.App.PatchPost(rpost.Id, patchWithNoMention)
|
||||
rpost, err = th.App.PatchPost(th.Context, rpost.Id, patchWithNoMention)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProps(), model.StringInterface{})
|
||||
|
||||
patchWithMention := &model.PostPatch{Message: model.NewString("This patch has a mention now @here")}
|
||||
|
||||
rpost, err = th.App.PatchPost(rpost.Id, patchWithMention)
|
||||
rpost, err = th.App.PatchPost(th.Context, rpost.Id, patchWithMention)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, rpost.GetProp(model.POST_PROPS_MENTION_HIGHLIGHT_DISABLED), true)
|
||||
|
||||
@@ -858,7 +858,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr := th.App.CreatePostAsUser(post, "", true)
|
||||
_, appErr := th.App.CreatePostAsUser(th.Context, post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, err := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
@@ -882,7 +882,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr := th.App.CreatePostAsUser(post, "", true)
|
||||
_, appErr := th.App.CreatePostAsUser(th.Context, post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, err := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
@@ -913,7 +913,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
require.NoError(t, nErr)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr = th.App.CreatePostAsUser(post, "", true)
|
||||
_, appErr = th.App.CreatePostAsUser(th.Context, post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, nErr := th.App.Srv().Store.Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
@@ -935,7 +935,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
UserId: user.Id,
|
||||
}
|
||||
|
||||
_, appErr := th.App.CreatePostAsUser(post, "", true)
|
||||
_, appErr := th.App.CreatePostAsUser(th.Context, post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
testlib.AssertLog(t, th.LogBuffer, mlog.LevelWarn, "Failed to get membership")
|
||||
@@ -958,7 +958,7 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
UserId: bot.UserId,
|
||||
}
|
||||
|
||||
_, appErr = th.App.CreatePostAsUser(post, "", true)
|
||||
_, appErr = th.App.CreatePostAsUser(th.Context, post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
testlib.AssertNoLog(t, th.LogBuffer, mlog.LevelWarn, "Failed to get membership")
|
||||
@@ -971,9 +971,9 @@ func TestPatchPostInArchivedChannel(t *testing.T) {
|
||||
|
||||
archivedChannel := th.CreateChannel(th.BasicTeam)
|
||||
post := th.CreatePost(archivedChannel)
|
||||
th.App.DeleteChannel(archivedChannel, "")
|
||||
th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
|
||||
_, err := th.App.PatchPost(post.Id, &model.PostPatch{IsPinned: model.NewBool(true)})
|
||||
_, err := th.App.PatchPost(th.Context, post.Id, &model.PostPatch{IsPinned: model.NewBool(true)})
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "api.post.patch_post.can_not_update_post_in_deleted.error", err.Id)
|
||||
}
|
||||
@@ -1002,14 +1002,14 @@ func TestUpdatePost(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false, true)
|
||||
rpost, err := th.App.CreatePost(th.Context, post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
assert.NotEqual(t, "", rpost.Message)
|
||||
|
||||
post.Id = rpost.Id
|
||||
post.Message = ""
|
||||
|
||||
rpost, err = th.App.UpdatePost(post, false)
|
||||
rpost, err = th.App.UpdatePost(th.Context, post, false)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "", rpost.Message)
|
||||
})
|
||||
@@ -1024,7 +1024,7 @@ func TestSearchPostsInTeamForUser(t *testing.T) {
|
||||
|
||||
posts := make([]*model.Post, 7)
|
||||
for i := 0; i < cap(posts); i++ {
|
||||
post, err := th.App.CreatePost(&model.Post{
|
||||
post, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: searchTerm,
|
||||
@@ -1057,7 +1057,7 @@ func TestSearchPostsInTeamForUser(t *testing.T) {
|
||||
|
||||
page := 0
|
||||
|
||||
results, err := th.App.SearchPostsInTeamForUser(searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
results, err := th.App.SearchPostsInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{
|
||||
@@ -1077,7 +1077,7 @@ func TestSearchPostsInTeamForUser(t *testing.T) {
|
||||
|
||||
page := 1
|
||||
|
||||
results, err := th.App.SearchPostsInTeamForUser(searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
results, err := th.App.SearchPostsInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{}, results.Order)
|
||||
@@ -1107,7 +1107,7 @@ func TestSearchPostsInTeamForUser(t *testing.T) {
|
||||
th.App.Srv().SearchEngine.ElasticsearchEngine = nil
|
||||
}()
|
||||
|
||||
results, err := th.App.SearchPostsInTeamForUser(searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
results, err := th.App.SearchPostsInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, resultsPage, results.Order)
|
||||
@@ -1135,7 +1135,7 @@ func TestSearchPostsInTeamForUser(t *testing.T) {
|
||||
th.App.Srv().SearchEngine.ElasticsearchEngine = nil
|
||||
}()
|
||||
|
||||
results, err := th.App.SearchPostsInTeamForUser(searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
results, err := th.App.SearchPostsInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, resultsPage, results.Order)
|
||||
@@ -1159,7 +1159,7 @@ func TestSearchPostsInTeamForUser(t *testing.T) {
|
||||
th.App.Srv().SearchEngine.ElasticsearchEngine = nil
|
||||
}()
|
||||
|
||||
results, err := th.App.SearchPostsInTeamForUser(searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
results, err := th.App.SearchPostsInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{
|
||||
@@ -1191,7 +1191,7 @@ func TestSearchPostsInTeamForUser(t *testing.T) {
|
||||
th.App.Srv().SearchEngine.ElasticsearchEngine = nil
|
||||
}()
|
||||
|
||||
results, err := th.App.SearchPostsInTeamForUser(searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
results, err := th.App.SearchPostsInTeamForUser(th.Context, searchTerm, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{}, results.Order)
|
||||
@@ -1210,19 +1210,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test3",
|
||||
@@ -1247,19 +1247,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
user2.NotifyProps[model.MENTION_KEYS_NOTIFY_PROP] = "apple"
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "apple",
|
||||
@@ -1286,19 +1286,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
user2.NotifyProps[model.CHANNEL_MENTIONS_NOTIFY_PROP] = "true"
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@channel",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@all",
|
||||
@@ -1325,19 +1325,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
user2.NotifyProps[model.CHANNEL_MENTIONS_NOTIFY_PROP] = "false"
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@channel",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@all",
|
||||
@@ -1367,19 +1367,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
}, channel.Id, user2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@channel",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "@all",
|
||||
@@ -1404,33 +1404,33 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
user2.NotifyProps[model.COMMENTS_NOTIFY_PROP] = model.COMMENTS_NOTIFY_ROOT
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post1.Id,
|
||||
Message: "test2",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
post3, err := th.App.CreatePost(&model.Post{
|
||||
post3, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test3",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post3.Id,
|
||||
Message: "test4",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post3.Id,
|
||||
@@ -1458,33 +1458,33 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
user2.NotifyProps[model.COMMENTS_NOTIFY_PROP] = model.COMMENTS_NOTIFY_ANY
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post1.Id,
|
||||
Message: "test2",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
post3, err := th.App.CreatePost(&model.Post{
|
||||
post3, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test3",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post3.Id,
|
||||
Message: "test4",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post3.Id,
|
||||
@@ -1510,7 +1510,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
@@ -1520,7 +1520,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
},
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
@@ -1530,7 +1530,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
},
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test3",
|
||||
@@ -1559,14 +1559,14 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
channel, err := th.App.createDirectChannel(user1.Id, user2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
@@ -1594,19 +1594,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
_, err := th.App.CreatePost(&model.Post{
|
||||
_, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
post2, err := th.App.CreatePost(&model.Post{
|
||||
post2, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
@@ -1631,13 +1631,13 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
@@ -1664,26 +1664,26 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
user2.NotifyProps[model.COMMENTS_NOTIFY_PROP] = model.COMMENTS_NOTIFY_ANY
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test1",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post1.Id,
|
||||
Message: "test2",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
post3, err := th.App.CreatePost(&model.Post{
|
||||
post3, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test3",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post1.Id,
|
||||
@@ -1709,19 +1709,19 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test1",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
@@ -1751,7 +1751,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
numPosts := 215
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
@@ -1759,7 +1759,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
for i := 0; i < numPosts-1; i++ {
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
@@ -1786,7 +1786,7 @@ func TestFillInPostProps(t *testing.T) {
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test123123 @group1 @group2 blah blah blah",
|
||||
@@ -1811,14 +1811,14 @@ func TestFillInPostProps(t *testing.T) {
|
||||
Password: "Password1",
|
||||
EmailVerified: true,
|
||||
}
|
||||
guest, err := th.App.CreateGuest(guest)
|
||||
guest, err := th.App.CreateGuest(th.Context, guest)
|
||||
require.Nil(t, err)
|
||||
th.LinkUserToTeam(guest, th.BasicTeam)
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(guest, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: guest.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test123123 @group1 @group2 blah blah blah",
|
||||
@@ -1844,14 +1844,14 @@ func TestFillInPostProps(t *testing.T) {
|
||||
Password: "Password1",
|
||||
EmailVerified: true,
|
||||
}
|
||||
guest, err := th.App.CreateGuest(guest)
|
||||
guest, err := th.App.CreateGuest(th.Context, guest)
|
||||
require.Nil(t, err)
|
||||
th.LinkUserToTeam(guest, th.BasicTeam)
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(guest, channel)
|
||||
|
||||
post1, err := th.App.CreatePost(&model.Post{
|
||||
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: guest.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test123123 @group1 @group2 blah blah blah",
|
||||
@@ -1876,14 +1876,14 @@ func TestThreadMembership(t *testing.T) {
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
postRoot, err := th.App.CreatePost(&model.Post{
|
||||
postRoot, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "root post",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: postRoot.Id,
|
||||
@@ -1900,14 +1900,14 @@ func TestThreadMembership(t *testing.T) {
|
||||
require.NoError(t, err2)
|
||||
require.Len(t, memberships, 1)
|
||||
|
||||
post2, err := th.App.CreatePost(&model.Post{
|
||||
post2, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "second post",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user2.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post2.Id,
|
||||
@@ -1938,25 +1938,25 @@ func TestFollowThreadSkipsParticipants(t *testing.T) {
|
||||
user2 := th.BasicUser2
|
||||
sysadmin := th.SystemAdminUser
|
||||
|
||||
appErr := th.App.JoinChannel(channel, user.Id)
|
||||
appErr := th.App.JoinChannel(th.Context, channel, user.Id)
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.JoinChannel(channel, user2.Id)
|
||||
appErr = th.App.JoinChannel(th.Context, channel, user2.Id)
|
||||
require.Nil(t, appErr)
|
||||
_, appErr = th.App.JoinUserToTeam(th.BasicTeam, sysadmin, sysadmin.Id)
|
||||
_, appErr = th.App.JoinUserToTeam(th.Context, th.BasicTeam, sysadmin, sysadmin.Id)
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.JoinChannel(channel, sysadmin.Id)
|
||||
appErr = th.App.JoinChannel(th.Context, channel, sysadmin.Id)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
p1, err := th.App.CreatePost(&model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + sysadmin.Username}, channel, false, false)
|
||||
p1, err := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + sysadmin.Username}, channel, false, false)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(&model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, false, false)
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
thread, err := th.App.GetThreadForUser(user.Id, th.BasicTeam.Id, p1.Id, false)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, thread.Participants, 1) // length should be 1, the original poster, since sysadmin was just mentioned but didn't post
|
||||
|
||||
_, err = th.App.CreatePost(&model.Post{RootId: p1.Id, UserId: sysadmin.Id, ChannelId: channel.Id, Message: "sysadmin reply"}, channel, false, false)
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: sysadmin.Id, ChannelId: channel.Id, Message: "sysadmin reply"}, channel, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
thread, err = th.App.GetThreadForUser(user.Id, th.BasicTeam.Id, p1.Id, false)
|
||||
@@ -1988,16 +1988,16 @@ func TestAutofollowBasedOnRootPost(t *testing.T) {
|
||||
channel := th.BasicChannel
|
||||
user := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
appErr := th.App.JoinChannel(channel, user.Id)
|
||||
appErr := th.App.JoinChannel(th.Context, channel, user.Id)
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.JoinChannel(channel, user2.Id)
|
||||
appErr = th.App.JoinChannel(th.Context, channel, user2.Id)
|
||||
require.Nil(t, appErr)
|
||||
p1, err := th.App.CreatePost(&model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, false, false)
|
||||
p1, err := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, false, false)
|
||||
require.Nil(t, err)
|
||||
m, e := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e)
|
||||
require.Len(t, m, 0)
|
||||
_, err2 := th.App.CreatePost(&model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, false, false)
|
||||
_, err2 := th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, false, false)
|
||||
require.Nil(t, err2)
|
||||
m, e = th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e)
|
||||
@@ -2018,13 +2018,13 @@ func TestViewChannelShouldNotUpdateThreads(t *testing.T) {
|
||||
channel := th.BasicChannel
|
||||
user := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
appErr := th.App.JoinChannel(channel, user.Id)
|
||||
appErr := th.App.JoinChannel(th.Context, channel, user.Id)
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.JoinChannel(channel, user2.Id)
|
||||
appErr = th.App.JoinChannel(th.Context, channel, user2.Id)
|
||||
require.Nil(t, appErr)
|
||||
p1, err := th.App.CreatePost(&model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, false, false)
|
||||
p1, err := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, false, false)
|
||||
require.Nil(t, err)
|
||||
_, err2 := th.App.CreatePost(&model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, false, false)
|
||||
_, err2 := th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, false, false)
|
||||
require.Nil(t, err2)
|
||||
m, e := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e)
|
||||
@@ -2053,16 +2053,16 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
t.Run("should only return root posts, enriched", func(t *testing.T) {
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
defer th.App.DeleteChannel(channel, user1.Id)
|
||||
defer th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
|
||||
postRoot, err := th.App.CreatePost(&model.Post{
|
||||
postRoot, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "root post",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: postRoot.Id,
|
||||
@@ -2098,9 +2098,9 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
defer th.App.DeleteChannel(channel, user1.Id)
|
||||
defer th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
|
||||
postRoot, err := th.App.CreatePost(&model.Post{
|
||||
postRoot, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "root post",
|
||||
@@ -2116,7 +2116,7 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
}()
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: postRoot.Id,
|
||||
@@ -2150,14 +2150,14 @@ func TestReplyToPostWithLag(t *testing.T) {
|
||||
mainHelper.ToggleReplicasOn()
|
||||
defer mainHelper.ToggleReplicasOff()
|
||||
|
||||
root, appErr := th.App.CreatePost(&model.Post{
|
||||
root, appErr := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "root post",
|
||||
}, th.BasicChannel, false, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
reply, appErr := th.App.CreatePost(&model.Post{
|
||||
reply, appErr := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: th.BasicUser2.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
RootId: root.Id,
|
||||
@@ -2183,7 +2183,7 @@ func TestSharedChannelSyncForPostActions(t *testing.T) {
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
|
||||
_, err := th.App.CreatePost(&model.Post{
|
||||
_, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "Hello folks",
|
||||
@@ -2207,14 +2207,14 @@ func TestSharedChannelSyncForPostActions(t *testing.T) {
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
|
||||
post, err := th.App.CreatePost(&model.Post{
|
||||
post, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "Hello folks",
|
||||
}, channel, false, true)
|
||||
require.Nil(t, err, "Creating a post should not error")
|
||||
|
||||
_, err = th.App.UpdatePost(post, true)
|
||||
_, err = th.App.UpdatePost(th.Context, post, true)
|
||||
require.Nil(t, err, "Updating a post should not error")
|
||||
|
||||
assert.Len(t, remoteClusterService.notifications, 2)
|
||||
@@ -2235,7 +2235,7 @@ func TestSharedChannelSyncForPostActions(t *testing.T) {
|
||||
|
||||
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
||||
|
||||
post, err := th.App.CreatePost(&model.Post{
|
||||
post, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "Hello folks",
|
||||
|
||||
Ссылка в новой задаче
Block a user