MM-61484 - Deleting scheduled posts when permanently deleting a user (#29152)
* Deleting scheduled posts when permanently deleting a user * Updated tests * CI * Testing CI * Restored a test change * Skipping flaky test
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5e47c97db4
Коммит
c79a8a8b4a
@@ -152,6 +152,24 @@ func (_m *ScheduledPostStore) GetScheduledPostsForUser(userId string, teamId str
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteByUser provides a mock function with given fields: userId
|
||||
func (_m *ScheduledPostStore) PermanentDeleteByUser(userId string) error {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for PermanentDeleteByUser")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(userId)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// PermanentlyDeleteScheduledPosts provides a mock function with given fields: scheduledPostIDs
|
||||
func (_m *ScheduledPostStore) PermanentlyDeleteScheduledPosts(scheduledPostIDs []string) error {
|
||||
ret := _m.Called(scheduledPostIDs)
|
||||
|
||||
@@ -20,6 +20,7 @@ func TestScheduledPostStore(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
t.Run("PermanentlyDeleteScheduledPosts", func(t *testing.T) { testPermanentlyDeleteScheduledPosts(t, rctx, ss, s) })
|
||||
t.Run("UpdatedScheduledPost", func(t *testing.T) { testUpdatedScheduledPost(t, rctx, ss, s) })
|
||||
t.Run("UpdateOldScheduledPosts", func(t *testing.T) { testUpdateOldScheduledPosts(t, rctx, ss, s) })
|
||||
t.Run("PermanentDeleteByUser", func(t *testing.T) { testPermanentDeleteScheduledPostsByUser(t, rctx, ss, s) })
|
||||
}
|
||||
|
||||
func testCreateScheduledPost(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore) {
|
||||
@@ -470,3 +471,84 @@ func testUpdateOldScheduledPosts(t *testing.T, rctx request.CTX, ss store.Store,
|
||||
assert.Equal(t, "", scheduledPosts[3].ErrorCode)
|
||||
})
|
||||
}
|
||||
|
||||
func testPermanentDeleteScheduledPostsByUser(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore) {
|
||||
t.Run("should delete all scheduled posts for a given user", func(t *testing.T) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create a scheduled post for the user
|
||||
scheduledPost := &model.ScheduledPost{
|
||||
Draft: model.Draft{
|
||||
CreateAt: model.GetMillis(),
|
||||
UserId: userId,
|
||||
ChannelId: model.NewId(),
|
||||
Message: "this is a scheduled post",
|
||||
},
|
||||
ScheduledAt: model.GetMillis() + 100000,
|
||||
}
|
||||
|
||||
createdScheduledPost, err := ss.ScheduledPost().CreateScheduledPost(scheduledPost)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, createdScheduledPost.Id)
|
||||
|
||||
// Delete scheduled posts for the user
|
||||
err = ss.ScheduledPost().PermanentDeleteByUser(userId)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Verify that no scheduled posts exist for the user
|
||||
scheduledPosts, err := ss.ScheduledPost().GetScheduledPostsForUser(userId, teamId)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, scheduledPosts)
|
||||
})
|
||||
|
||||
t.Run("should not fail if no scheduled posts exist for the user", func(t *testing.T) {
|
||||
userId := model.NewId()
|
||||
|
||||
// Attempt to delete scheduled posts for a user with no scheduled posts
|
||||
err := ss.ScheduledPost().PermanentDeleteByUser(userId)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("should handle multiple scheduled posts for the same user", func(t *testing.T) {
|
||||
userId := model.NewId()
|
||||
teamId := model.NewId()
|
||||
|
||||
// Create multiple scheduled posts for the user
|
||||
for i := 0; i < 3; i++ {
|
||||
scheduledPost := &model.ScheduledPost{
|
||||
Draft: model.Draft{
|
||||
CreateAt: model.GetMillis(),
|
||||
UserId: userId,
|
||||
ChannelId: model.NewId(),
|
||||
Message: "this is a scheduled post",
|
||||
},
|
||||
ScheduledAt: model.GetMillis() + 100000,
|
||||
}
|
||||
|
||||
createdScheduledPost, err := ss.ScheduledPost().CreateScheduledPost(scheduledPost)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, createdScheduledPost.Id)
|
||||
}
|
||||
|
||||
// Delete scheduled posts for the user
|
||||
err := ss.ScheduledPost().PermanentDeleteByUser(userId)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Verify that no scheduled posts exist for the user
|
||||
scheduledPosts, err := ss.ScheduledPost().GetScheduledPostsForUser(userId, teamId)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, scheduledPosts)
|
||||
})
|
||||
|
||||
t.Run("should handle empty user id", func(t *testing.T) {
|
||||
err := ss.ScheduledPost().PermanentDeleteByUser("")
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("should handle non-existing user id", func(t *testing.T) {
|
||||
nonExistingUserId := model.NewId()
|
||||
err := ss.ScheduledPost().PermanentDeleteByUser(nonExistingUserId)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user