diff options
author | George Goldberg <george@gberg.me> | 2017-09-15 17:35:55 +0100 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-09-15 09:35:55 -0700 |
commit | 8195c80aa12136838ff4491fac989e0b946382b1 (patch) | |
tree | da24729af5acbd3349c75923d346cfa7aa9ad95c /store/sql_reaction_store_test.go | |
parent | 2628022275ef64fde95545abe4634b4bd7177844 (diff) | |
download | chat-8195c80aa12136838ff4491fac989e0b946382b1.tar.gz chat-8195c80aa12136838ff4491fac989e0b946382b1.tar.bz2 chat-8195c80aa12136838ff4491fac989e0b946382b1.zip |
PLT-7639: Batch delete methods for data retention. (#7444)
Diffstat (limited to 'store/sql_reaction_store_test.go')
-rw-r--r-- | store/sql_reaction_store_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/store/sql_reaction_store_test.go b/store/sql_reaction_store_test.go index ac2590ea4..ebc09dc9b 100644 --- a/store/sql_reaction_store_test.go +++ b/store/sql_reaction_store_test.go @@ -294,3 +294,58 @@ func TestReactionDeleteAllWithEmojiName(t *testing.T) { t.Fatal("post shouldn't have reactions any more") } } + +func TestReactionStorePermanentDeleteBatch(t *testing.T) { + Setup() + + post := Must(store.Post().Save(&model.Post{ + ChannelId: model.NewId(), + UserId: model.NewId(), + })).(*model.Post) + + reactions := []*model.Reaction{ + { + UserId: model.NewId(), + PostId: post.Id, + EmojiName: "sad", + CreateAt: 1000, + }, + { + UserId: model.NewId(), + PostId: post.Id, + EmojiName: "sad", + CreateAt: 1500, + }, + { + UserId: model.NewId(), + PostId: post.Id, + EmojiName: "sad", + CreateAt: 2000, + }, + { + UserId: model.NewId(), + PostId: post.Id, + EmojiName: "sad", + CreateAt: 2000, + }, + } + + // Need to hang on to a reaction to delete later in order to clear the cache, as "allowFromCache" isn't honoured any more. + var lastReaction *model.Reaction + for _, reaction := range reactions { + lastReaction = Must(store.Reaction().Save(reaction)).(*model.Reaction) + } + + if returned := Must(store.Reaction().GetForPost(post.Id, false)).([]*model.Reaction); len(returned) != 4 { + t.Fatal("expected 4 reactions") + } + + Must(store.Reaction().PermanentDeleteBatch(1800, 1000)) + + // This is to force a clear of the cache. + Must(store.Reaction().Delete(lastReaction)) + + if returned := Must(store.Reaction().GetForPost(post.Id, false)).([]*model.Reaction); len(returned) != 1 { + t.Fatalf("expected 1 reaction. Got: %v", len(returned)) + } +} |