[MM-61467] Fix errcheck linter issues in post_test.go (#30686)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
210bdfcb72
Коммит
5ee308bd83
@@ -99,7 +99,6 @@ issues:
|
||||
channels/app/platform/session.go|\
|
||||
channels/app/platform/status.go|\
|
||||
channels/app/platform/web_hub_test.go|\
|
||||
channels/app/post_test.go|\
|
||||
channels/app/slashcommands/command_test.go|\
|
||||
channels/app/slashcommands/helper_test.go|\
|
||||
channels/app/team.go|\
|
||||
|
||||
@@ -324,7 +324,8 @@ func TestUpdatePostInArchivedChannel(t *testing.T) {
|
||||
|
||||
archivedChannel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
post := th.CreatePost(archivedChannel)
|
||||
th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
appErr := th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, err := th.App.UpdatePost(th.Context, post, &model.UpdatePostOptions{SafeUpdate: true})
|
||||
require.NotNil(t, err)
|
||||
@@ -560,6 +561,10 @@ func TestPostChannelMentions(t *testing.T) {
|
||||
TeamId: th.BasicTeam.Id,
|
||||
}, false)
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
appErr := th.App.PermanentDeleteChannel(th.Context, channelToMention)
|
||||
require.Nil(t, appErr)
|
||||
}()
|
||||
channelToMention2, err := th.App.CreateChannel(th.Context, &model.Channel{
|
||||
DisplayName: "Mention Test2",
|
||||
Name: "mention-test2",
|
||||
@@ -567,8 +572,10 @@ func TestPostChannelMentions(t *testing.T) {
|
||||
TeamId: th.BasicTeam.Id,
|
||||
}, false)
|
||||
require.Nil(t, err)
|
||||
defer th.App.PermanentDeleteChannel(th.Context, channelToMention)
|
||||
defer th.App.PermanentDeleteChannel(th.Context, channelToMention2)
|
||||
defer func() {
|
||||
appErr := th.App.PermanentDeleteChannel(th.Context, channelToMention2)
|
||||
require.Nil(t, appErr)
|
||||
}()
|
||||
|
||||
_, err = th.App.AddUserToChannel(th.Context, user, channel, false)
|
||||
require.Nil(t, err)
|
||||
@@ -743,8 +750,10 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
|
||||
info1, err := th.App.DoUploadFile(th.Context, time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data, true)
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info1.Id)
|
||||
th.App.RemoveFile(info1.Path)
|
||||
err := th.App.Srv().Store().FileInfo().PermanentDelete(th.Context, info1.Id)
|
||||
require.NoError(t, err)
|
||||
appErr := th.App.RemoveFile(info1.Path)
|
||||
require.Nil(t, appErr)
|
||||
}()
|
||||
|
||||
post := &model.Post{
|
||||
@@ -777,7 +786,8 @@ func TestDeletePostInArchivedChannel(t *testing.T) {
|
||||
|
||||
archivedChannel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
post := th.CreatePost(archivedChannel)
|
||||
th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
appErr := th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, err := th.App.DeletePost(th.Context, post.Id, "")
|
||||
require.NotNil(t, err)
|
||||
@@ -1007,8 +1017,8 @@ func TestCreatePost(t *testing.T) {
|
||||
|
||||
user1 := th.CreateUser()
|
||||
user2 := th.CreateUser()
|
||||
dm, err := th.App.createDirectChannel(th.Context, user1.Id, user2.Id)
|
||||
require.Nil(t, err)
|
||||
dm, appErr := th.App.createDirectChannel(th.Context, user1.Id, user2.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.NotNil(t, dm)
|
||||
|
||||
// we can't create direct channels with remote users, so we
|
||||
@@ -1027,16 +1037,16 @@ func TestCreatePost(t *testing.T) {
|
||||
|
||||
// and we update the channel to mark it as shared
|
||||
dm.Shared = model.NewPointer(true)
|
||||
_, cErr := th.Server.Store().Channel().Update(th.Context, dm)
|
||||
require.NoError(t, cErr)
|
||||
_, err := th.Server.Store().Channel().Update(th.Context, dm)
|
||||
require.NoError(t, err)
|
||||
|
||||
newPost := &model.Post{
|
||||
ChannelId: dm.Id,
|
||||
Message: "hello world",
|
||||
UserId: user1.Id,
|
||||
}
|
||||
createdPost, err := th.App.CreatePost(th.Context, newPost, dm, model.CreatePostFlags{})
|
||||
require.NotNil(t, err)
|
||||
createdPost, appErr := th.App.CreatePost(th.Context, newPost, dm, model.CreatePostFlags{})
|
||||
require.NotNil(t, appErr)
|
||||
require.Nil(t, createdPost)
|
||||
})
|
||||
|
||||
@@ -1047,8 +1057,8 @@ func TestCreatePost(t *testing.T) {
|
||||
user1 := th.CreateUser()
|
||||
user2 := th.CreateUser()
|
||||
user3 := th.CreateUser()
|
||||
gm, gErr := th.App.createGroupChannel(th.Context, []string{user1.Id, user2.Id, user3.Id})
|
||||
require.Nil(t, gErr)
|
||||
gm, appErr := th.App.createGroupChannel(th.Context, []string{user1.Id, user2.Id, user3.Id})
|
||||
require.Nil(t, appErr)
|
||||
require.NotNil(t, gm)
|
||||
|
||||
// we can't create group channels with remote users, so we
|
||||
@@ -1062,21 +1072,21 @@ func TestCreatePost(t *testing.T) {
|
||||
CreatorId: user1.Id,
|
||||
RemoteId: model.NewId(),
|
||||
}
|
||||
_, scErr := th.Server.Store().SharedChannel().Save(sc)
|
||||
require.NoError(t, scErr)
|
||||
_, err := th.Server.Store().SharedChannel().Save(sc)
|
||||
require.NoError(t, err)
|
||||
|
||||
// and we update the channel to mark it as shared
|
||||
gm.Shared = model.NewPointer(true)
|
||||
_, cErr := th.Server.Store().Channel().Update(th.Context, gm)
|
||||
require.NoError(t, cErr)
|
||||
_, err = th.Server.Store().Channel().Update(th.Context, gm)
|
||||
require.NoError(t, err)
|
||||
|
||||
newPost := &model.Post{
|
||||
ChannelId: gm.Id,
|
||||
Message: "hello world",
|
||||
UserId: user1.Id,
|
||||
}
|
||||
createdPost, err := th.App.CreatePost(th.Context, newPost, gm, model.CreatePostFlags{})
|
||||
require.NotNil(t, err)
|
||||
createdPost, appErr := th.App.CreatePost(th.Context, newPost, gm, model.CreatePostFlags{})
|
||||
require.NotNil(t, appErr)
|
||||
require.Nil(t, createdPost)
|
||||
})
|
||||
|
||||
@@ -1123,7 +1133,8 @@ func TestCreatePost(t *testing.T) {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
post := previewPost.Clone()
|
||||
th.App.UpdatePost(th.Context, post, nil)
|
||||
_, appErr := th.App.UpdatePost(th.Context, post, nil)
|
||||
require.Nil(t, appErr)
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -1315,15 +1326,15 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
UserId: bot.UserId,
|
||||
}
|
||||
|
||||
channelMemberBefore, nErr := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, nErr)
|
||||
channelMemberBefore, err := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, 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)
|
||||
require.NoError(t, nErr)
|
||||
channelMemberAfter, err := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, channelMemberAfter.LastViewedAt, channelMemberBefore.LastViewedAt)
|
||||
})
|
||||
@@ -1369,8 +1380,8 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
rootPost, appErr := th.App.CreatePostAsUser(th.Context, post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberBefore, nErr := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, nErr)
|
||||
channelMemberBefore, err := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
replyPost := &model.Post{
|
||||
@@ -1382,8 +1393,8 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
_, appErr = th.App.CreatePostAsUser(th.Context, replyPost, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, nErr := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, nErr)
|
||||
channelMemberAfter, err := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEqual(t, channelMemberAfter.LastViewedAt, channelMemberBefore.LastViewedAt)
|
||||
})
|
||||
@@ -1405,8 +1416,8 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
rootPost, appErr := th.App.CreatePostAsUser(th.Context, post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberBefore, nErr := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, nErr)
|
||||
channelMemberBefore, err := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
replyPost := &model.Post{
|
||||
@@ -1418,8 +1429,8 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
_, appErr = th.App.CreatePostAsUser(th.Context, replyPost, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, nErr := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, nErr)
|
||||
channelMemberAfter, err := th.App.Srv().Store().Channel().GetMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, channelMemberAfter.LastViewedAt, channelMemberBefore.LastViewedAt)
|
||||
})
|
||||
@@ -1431,7 +1442,8 @@ func TestPatchPostInArchivedChannel(t *testing.T) {
|
||||
|
||||
archivedChannel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
post := th.CreatePost(archivedChannel)
|
||||
th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
appErr := th.App.DeleteChannel(th.Context, archivedChannel, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, err := th.App.PatchPost(th.Context, post.Id, &model.PostPatch{IsPinned: model.NewPointer(true)}, nil)
|
||||
require.NotNil(t, err)
|
||||
@@ -2780,33 +2792,34 @@ func TestFollowThreadSkipsParticipants(t *testing.T) {
|
||||
appErr = th.App.JoinChannel(th.Context, channel, sysadmin.Id)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
p1, err := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + sysadmin.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
p1, appErr := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + sysadmin.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
threadMembership, err := th.App.GetThreadMembershipForUser(user.Id, p1.Id)
|
||||
require.Nil(t, err)
|
||||
thread, err := th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, err)
|
||||
threadMembership, appErr := th.App.GetThreadMembershipForUser(user.Id, p1.Id)
|
||||
require.Nil(t, appErr)
|
||||
thread, appErr := th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, appErr)
|
||||
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(th.Context, &model.Post{RootId: p1.Id, UserId: sysadmin.Id, ChannelId: channel.Id, Message: "sysadmin reply"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: sysadmin.Id, ChannelId: channel.Id, Message: "sysadmin reply"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
threadMembership, err = th.App.GetThreadMembershipForUser(user.Id, p1.Id)
|
||||
require.Nil(t, err)
|
||||
thread, err = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, err)
|
||||
threadMembership, appErr = th.App.GetThreadMembershipForUser(user.Id, p1.Id)
|
||||
require.Nil(t, appErr)
|
||||
thread, appErr = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, thread.Participants, 2) // length should be 2, the original poster and sysadmin, since sysadmin participated now
|
||||
|
||||
// another user follows the thread
|
||||
th.App.UpdateThreadFollowForUser(user2.Id, th.BasicTeam.Id, p1.Id, true)
|
||||
appErr = th.App.UpdateThreadFollowForUser(user2.Id, th.BasicTeam.Id, p1.Id, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
threadMembership, err = th.App.GetThreadMembershipForUser(user2.Id, p1.Id)
|
||||
require.Nil(t, err)
|
||||
thread, err = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, err)
|
||||
threadMembership, appErr = th.App.GetThreadMembershipForUser(user2.Id, p1.Id)
|
||||
require.Nil(t, appErr)
|
||||
thread, appErr = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, thread.Participants, 2) // length should be 2, since follow shouldn't update participant list, only user1 and sysadmin are participants
|
||||
for _, p := range thread.Participants {
|
||||
require.True(t, p.Id == sysadmin.Id || p.Id == user.Id)
|
||||
@@ -2814,15 +2827,15 @@ func TestFollowThreadSkipsParticipants(t *testing.T) {
|
||||
|
||||
oldID := threadMembership.PostId
|
||||
threadMembership.PostId = "notfound"
|
||||
_, err = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, http.StatusNotFound, err.StatusCode)
|
||||
_, appErr = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusNotFound, appErr.StatusCode)
|
||||
|
||||
threadMembership.Following = false
|
||||
threadMembership.PostId = oldID
|
||||
_, err = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, http.StatusNotFound, err.StatusCode)
|
||||
_, appErr = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusNotFound, appErr.StatusCode)
|
||||
}
|
||||
|
||||
func TestAutofollowBasedOnRootPost(t *testing.T) {
|
||||
@@ -2841,15 +2854,15 @@ func TestAutofollowBasedOnRootPost(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.JoinChannel(th.Context, channel, user2.Id)
|
||||
require.Nil(t, appErr)
|
||||
p1, err := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
m, e := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e)
|
||||
p1, appErr := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
m, err := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, m, 0)
|
||||
_, err2 := th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err2)
|
||||
m, e = th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
m, err = th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, m, 1)
|
||||
}
|
||||
|
||||
@@ -2869,20 +2882,21 @@ func TestViewChannelShouldNotUpdateThreads(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.JoinChannel(th.Context, channel, user2.Id)
|
||||
require.Nil(t, appErr)
|
||||
p1, err := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
_, err2 := th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err2)
|
||||
m, e := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e)
|
||||
p1, appErr := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
m, err := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.ViewChannel(th.Context, &model.ChannelView{
|
||||
_, appErr = th.App.ViewChannel(th.Context, &model.ChannelView{
|
||||
ChannelId: channel.Id,
|
||||
PrevChannelId: "",
|
||||
}, user2.Id, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
m1, e1 := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e1)
|
||||
m1, err := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, m[0].LastViewed, m1[0].LastViewed) // opening the channel shouldn't update threads
|
||||
}
|
||||
|
||||
@@ -2900,28 +2914,32 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
t.Run("should only return root posts, enriched", func(t *testing.T) {
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
defer th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
defer func() {
|
||||
appErr := th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
require.Nil(t, appErr)
|
||||
}()
|
||||
|
||||
postRoot, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
postRoot, appErr := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "root post",
|
||||
}, channel, model.CreatePostFlags{SetOnline: true})
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: postRoot.Id,
|
||||
Message: fmt.Sprintf("@%s", user2.Username),
|
||||
}, channel, model.CreatePostFlags{SetOnline: true})
|
||||
require.Nil(t, err)
|
||||
thread, nErr := th.App.Srv().Store().Thread().Get(postRoot.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.Nil(t, appErr)
|
||||
thread, err := th.App.Srv().Store().Thread().Get(postRoot.Id)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, thread.Participants, 1)
|
||||
th.App.MarkChannelAsUnreadFromPost(th.Context, postRoot.Id, user1.Id, true)
|
||||
l, err := th.App.GetPostsForChannelAroundLastUnread(th.Context, channel.Id, user1.Id, 10, 10, true, true, false)
|
||||
require.Nil(t, err)
|
||||
_, appErr = th.App.MarkChannelAsUnreadFromPost(th.Context, postRoot.Id, user1.Id, true)
|
||||
require.Nil(t, appErr)
|
||||
l, appErr := th.App.GetPostsForChannelAroundLastUnread(th.Context, channel.Id, user1.Id, 10, 10, true, true, false)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, l.Order, 1)
|
||||
require.EqualValues(t, 1, l.Posts[postRoot.Id].ReplyCount)
|
||||
require.EqualValues(t, []string{user1.Id}, []string{l.Posts[postRoot.Id].Participants[0].Id})
|
||||
@@ -2930,8 +2948,8 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
require.True(t, *l.Posts[postRoot.Id].IsFollowing)
|
||||
|
||||
// try extended fetch
|
||||
l, err = th.App.GetPostsForChannelAroundLastUnread(th.Context, channel.Id, user1.Id, 10, 10, true, true, true)
|
||||
require.Nil(t, err)
|
||||
l, appErr = th.App.GetPostsForChannelAroundLastUnread(th.Context, channel.Id, user1.Id, 10, 10, true, true, true)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, l.Order, 1)
|
||||
require.NotEmpty(t, l.Posts[postRoot.Id].Participants[0].Email)
|
||||
})
|
||||
@@ -2939,7 +2957,10 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
t.Run("Should not panic on unexpected db error", func(t *testing.T) {
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
th.AddUserToChannel(user2, channel)
|
||||
defer th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
defer func() {
|
||||
appErr := th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
require.Nil(t, appErr)
|
||||
}()
|
||||
|
||||
postRoot, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
@@ -2953,11 +2974,14 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
th.Server.Store().Post().PermanentDeleteByUser(th.Context, user1.Id)
|
||||
err := th.Server.Store().Post().PermanentDeleteByUser(th.Context, user1.Id)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
th.App.CreatePost(th.Context, &model.Post{
|
||||
// We're only testing that this doesn't panic, not checking the error
|
||||
// #nosec G104 - purposely not checking error as we're in a NotPanics block
|
||||
_, _ = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: postRoot.Id,
|
||||
@@ -2970,7 +2994,7 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
|
||||
t.Run("should sanitize participant data", func(t *testing.T) {
|
||||
id := model.NewId()
|
||||
user3, err := th.App.CreateUser(th.Context, &model.User{
|
||||
user3, appErr := th.App.CreateUser(th.Context, &model.User{
|
||||
Email: "success+" + id + "@simulator.amazonses.com",
|
||||
Username: "un_" + id,
|
||||
Nickname: "nn_" + id,
|
||||
@@ -2978,34 +3002,41 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
AuthService: "saml",
|
||||
EmailVerified: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, appErr)
|
||||
defer func() {
|
||||
appErr = th.App.PermanentDeleteUser(th.Context, user3)
|
||||
require.Nil(t, appErr)
|
||||
}()
|
||||
|
||||
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||
defer func() {
|
||||
appErr = th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
require.Nil(t, appErr)
|
||||
}()
|
||||
|
||||
th.LinkUserToTeam(user3, th.BasicTeam)
|
||||
th.AddUserToChannel(user3, channel)
|
||||
defer th.App.DeleteChannel(th.Context, channel, user1.Id)
|
||||
defer th.App.PermanentDeleteUser(th.Context, user3)
|
||||
|
||||
postRoot, err := th.App.CreatePost(th.Context, &model.Post{
|
||||
postRoot, appErr := th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "root post",
|
||||
}, channel, model.CreatePostFlags{SetOnline: true})
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{
|
||||
UserId: user3.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: postRoot.Id,
|
||||
Message: "reply",
|
||||
}, channel, model.CreatePostFlags{SetOnline: true})
|
||||
require.Nil(t, err)
|
||||
thread, nErr := th.App.Srv().Store().Thread().Get(postRoot.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.Nil(t, appErr)
|
||||
thread, err := th.App.Srv().Store().Thread().Get(postRoot.Id)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, thread.Participants, 1)
|
||||
|
||||
// extended fetch posts page
|
||||
l, err := th.App.GetPostsPage(model.GetPostsOptions{
|
||||
l, appErr := th.App.GetPostsPage(model.GetPostsOptions{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
PerPage: int(10),
|
||||
@@ -3013,16 +3044,17 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
CollapsedThreads: true,
|
||||
CollapsedThreadsExtended: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, l.Order, 1)
|
||||
require.NotEmpty(t, l.Posts[postRoot.Id].Participants[0].Email)
|
||||
require.Empty(t, l.Posts[postRoot.Id].Participants[0].AuthData)
|
||||
|
||||
th.App.MarkChannelAsUnreadFromPost(th.Context, postRoot.Id, user1.Id, true)
|
||||
_, appErr = th.App.MarkChannelAsUnreadFromPost(th.Context, postRoot.Id, user1.Id, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// extended fetch posts around
|
||||
l, err = th.App.GetPostsForChannelAroundLastUnread(th.Context, channel.Id, user1.Id, 10, 10, true, true, true)
|
||||
require.Nil(t, err)
|
||||
l, appErr = th.App.GetPostsForChannelAroundLastUnread(th.Context, channel.Id, user1.Id, 10, 10, true, true, true)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, l.Order, 1)
|
||||
require.NotEmpty(t, l.Posts[postRoot.Id].Participants[0].Email)
|
||||
require.Empty(t, l.Posts[postRoot.Id].Participants[0].AuthData)
|
||||
@@ -3034,8 +3066,8 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
||||
CollapsedThreadsExtended: true,
|
||||
}
|
||||
|
||||
l, err = th.App.GetPostThread(postRoot.Id, opts, user1.Id)
|
||||
require.Nil(t, err)
|
||||
l, appErr = th.App.GetPostThread(postRoot.Id, opts, user1.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, l.Order, 2)
|
||||
require.NotEmpty(t, l.Posts[postRoot.Id].Participants[0].Email)
|
||||
require.Empty(t, l.Posts[postRoot.Id].Participants[0].AuthData)
|
||||
@@ -3059,7 +3091,10 @@ func TestReplyToPostWithLag(t *testing.T) {
|
||||
t.Run("replication lag time great than reply time", func(t *testing.T) {
|
||||
err := mainHelper.SetReplicationLagForTesting(5)
|
||||
require.NoError(t, err)
|
||||
defer mainHelper.SetReplicationLagForTesting(0)
|
||||
defer func() {
|
||||
err := mainHelper.SetReplicationLagForTesting(0)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
mainHelper.ToggleReplicasOn()
|
||||
defer mainHelper.ToggleReplicasOff()
|
||||
|
||||
@@ -3181,28 +3216,28 @@ func TestAutofollowOnPostingAfterUnfollow(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.JoinChannel(th.Context, channel, user2.Id)
|
||||
require.Nil(t, appErr)
|
||||
p1, err := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user2.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "reply"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
p1, appErr := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user2.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "reply"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// unfollow thread
|
||||
m, nErr := th.App.Srv().Store().Thread().MaintainMembership(user.Id, p1.Id, store.ThreadMembershipOpts{
|
||||
m, err := th.App.Srv().Store().Thread().MaintainMembership(user.Id, p1.Id, store.ThreadMembershipOpts{
|
||||
Following: false,
|
||||
UpdateFollowing: true,
|
||||
})
|
||||
require.NoError(t, nErr)
|
||||
require.NoError(t, err)
|
||||
require.False(t, m.Following)
|
||||
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "another reply"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "another reply"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// User should be following thread after posting in it, even after previously
|
||||
// unfollowing it, if ThreadAutoFollow is true
|
||||
m, err = th.App.GetThreadMembershipForUser(user.Id, p1.Id)
|
||||
require.Nil(t, err)
|
||||
m, appErr = th.App.GetThreadMembershipForUser(user.Id, p1.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.True(t, m.Following)
|
||||
}
|
||||
|
||||
@@ -3286,36 +3321,36 @@ func TestShouldNotRefollowOnOthersReply(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.JoinChannel(th.Context, channel, user2.Id)
|
||||
require.Nil(t, appErr)
|
||||
p1, err := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user2.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
p1, appErr := th.App.CreatePost(th.Context, &model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user2.Id, ChannelId: channel.Id, Message: "Hola"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// User2 unfollows thread
|
||||
m, nErr := th.App.Srv().Store().Thread().MaintainMembership(user2.Id, p1.Id, store.ThreadMembershipOpts{
|
||||
m, err := th.App.Srv().Store().Thread().MaintainMembership(user2.Id, p1.Id, store.ThreadMembershipOpts{
|
||||
Following: false,
|
||||
UpdateFollowing: true,
|
||||
})
|
||||
require.NoError(t, nErr)
|
||||
require.NoError(t, err)
|
||||
require.False(t, m.Following)
|
||||
|
||||
// user posts in the thread
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "another reply"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "another reply"}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// User2 should still not be following the thread because they manually
|
||||
// unfollowed the thread
|
||||
m, err = th.App.GetThreadMembershipForUser(user2.Id, p1.Id)
|
||||
require.Nil(t, err)
|
||||
m, appErr = th.App.GetThreadMembershipForUser(user2.Id, p1.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.False(t, m.Following)
|
||||
|
||||
// user posts in the thread mentioning user2
|
||||
_, err = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "reply with mention @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, err)
|
||||
_, appErr = th.App.CreatePost(th.Context, &model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "reply with mention @" + user2.Username}, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// User2 should now be following the thread because they were explicitly mentioned
|
||||
m, err = th.App.GetThreadMembershipForUser(user2.Id, p1.Id)
|
||||
require.Nil(t, err)
|
||||
m, appErr = th.App.GetThreadMembershipForUser(user2.Id, p1.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.True(t, m.Following)
|
||||
}
|
||||
|
||||
@@ -3777,8 +3812,8 @@ func TestPermanentDeletePost(t *testing.T) {
|
||||
filename := "test"
|
||||
data := []byte("abcd")
|
||||
|
||||
info1, err := th.App.DoUploadFile(th.Context, time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data, true)
|
||||
require.Nil(t, err)
|
||||
info1, appErr := th.App.DoUploadFile(th.Context, time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
post := &model.Post{
|
||||
Message: "asd",
|
||||
@@ -3789,30 +3824,30 @@ func TestPermanentDeletePost(t *testing.T) {
|
||||
FileIds: []string{info1.Id},
|
||||
}
|
||||
|
||||
post, err = th.App.CreatePost(th.Context, post, th.BasicChannel, model.CreatePostFlags{SetOnline: true})
|
||||
assert.Nil(t, err)
|
||||
post, appErr = th.App.CreatePost(th.Context, post, th.BasicChannel, model.CreatePostFlags{SetOnline: true})
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
infos, sErr := th.App.Srv().Store().FileInfo().GetForPost(post.Id, true, true, false)
|
||||
require.NoError(t, sErr)
|
||||
infos, err := th.App.Srv().Store().FileInfo().GetForPost(post.Id, true, true, false)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, infos, 1)
|
||||
|
||||
// Soft delete the post.
|
||||
_, err = th.App.DeletePost(th.Context, post.Id, userID)
|
||||
assert.Nil(t, err)
|
||||
_, appErr = th.App.DeletePost(th.Context, post.Id, userID)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Wait for the cleanup routine to finish.
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
||||
// Delete the post.
|
||||
err = th.App.PermanentDeletePost(th.Context, post.Id, userID)
|
||||
assert.Nil(t, err)
|
||||
appErr = th.App.PermanentDeletePost(th.Context, post.Id, userID)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Check that the post can no longer be reached.
|
||||
_, err = th.App.GetSinglePost(th.Context, post.Id, true)
|
||||
assert.NotNil(t, err)
|
||||
_, appErr = th.App.GetSinglePost(th.Context, post.Id, true)
|
||||
assert.NotNil(t, appErr)
|
||||
|
||||
infos, sErr = th.App.Srv().Store().FileInfo().GetForPost(post.Id, true, true, false)
|
||||
require.NoError(t, sErr)
|
||||
infos, err = th.App.Srv().Store().FileInfo().GetForPost(post.Id, true, true, false)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, infos, 0)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user