From 33b8b72a026c54f121f1d0f0370d9ad2e6220a61 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 7 Mar 2017 09:37:00 -0500 Subject: Adding index and cache to reactinos store (#5654) --- store/sql_reaction_store_test.go | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'store/sql_reaction_store_test.go') diff --git a/store/sql_reaction_store_test.go b/store/sql_reaction_store_test.go index 5a1cb2d67..01ce14e65 100644 --- a/store/sql_reaction_store_test.go +++ b/store/sql_reaction_store_test.go @@ -4,8 +4,9 @@ package store import ( - "github.com/mattermost/platform/model" "testing" + + "github.com/mattermost/platform/model" ) func TestReactionSave(t *testing.T) { @@ -108,7 +109,7 @@ func TestReactionDelete(t *testing.T) { t.Fatal(result.Err) } - if result := <-store.Reaction().GetForPost(post.Id); result.Err != nil { + if result := <-store.Reaction().GetForPost(post.Id, false); result.Err != nil { t.Fatal(result.Err) } else if len(result.Data.([]*model.Reaction)) != 0 { t.Fatal("should've deleted reaction") @@ -155,7 +156,32 @@ func TestReactionGetForPost(t *testing.T) { Must(store.Reaction().Save(reaction)) } - if result := <-store.Reaction().GetForPost(postId); result.Err != nil { + if result := <-store.Reaction().GetForPost(postId, false); result.Err != nil { + t.Fatal(result.Err) + } else if returned := result.Data.([]*model.Reaction); len(returned) != 3 { + t.Fatal("should've returned 3 reactions") + } else { + for _, reaction := range reactions { + found := false + + for _, returnedReaction := range returned { + if returnedReaction.UserId == reaction.UserId && returnedReaction.PostId == reaction.PostId && + returnedReaction.EmojiName == reaction.EmojiName { + found = true + break + } + } + + if !found && reaction.PostId == postId { + t.Fatalf("should've returned reaction for post %v", reaction) + } else if found && reaction.PostId != postId { + t.Fatal("shouldn't have returned reaction for another post") + } + } + } + + // Should return cached item + if result := <-store.Reaction().GetForPost(postId, true); result.Err != nil { t.Fatal(result.Err) } else if returned := result.Data.([]*model.Reaction); len(returned) != 3 { t.Fatal("should've returned 3 reactions") @@ -237,7 +263,7 @@ func TestReactionDeleteAllWithEmojiName(t *testing.T) { } // check that the reactions were deleted - if returned := Must(store.Reaction().GetForPost(post.Id)).([]*model.Reaction); len(returned) != 1 { + if returned := Must(store.Reaction().GetForPost(post.Id, false)).([]*model.Reaction); len(returned) != 1 { t.Fatal("should've only removed reactions with emoji name") } else { for _, reaction := range returned { @@ -247,11 +273,11 @@ func TestReactionDeleteAllWithEmojiName(t *testing.T) { } } - if returned := Must(store.Reaction().GetForPost(post2.Id)).([]*model.Reaction); len(returned) != 1 { + if returned := Must(store.Reaction().GetForPost(post2.Id, false)).([]*model.Reaction); len(returned) != 1 { t.Fatal("should've only removed reactions with emoji name") } - if returned := Must(store.Reaction().GetForPost(post3.Id)).([]*model.Reaction); len(returned) != 0 { + if returned := Must(store.Reaction().GetForPost(post3.Id, false)).([]*model.Reaction); len(returned) != 0 { t.Fatal("should've only removed reactions with emoji name") } -- cgit v1.2.3-1-g7c22