From 4f4a765e7d0bbfdfecc0c52ae4be35f8d3b737ca Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 23 Jan 2018 11:04:44 -0500 Subject: ABC-90 Add POST /emoji/search and GET /emoji/autocomplete API endpoints (#8125) * Add POST /emoji/search and GET /emoji/autocomplete API endpoints * Add constant to be clearer --- store/storetest/emoji_store.go | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'store/storetest/emoji_store.go') diff --git a/store/storetest/emoji_store.go b/store/storetest/emoji_store.go index a862440e5..9e4dbaa6e 100644 --- a/store/storetest/emoji_store.go +++ b/store/storetest/emoji_store.go @@ -18,6 +18,7 @@ func TestEmojiStore(t *testing.T, ss store.Store) { t.Run("EmojiGet", func(t *testing.T) { testEmojiGet(t, ss) }) t.Run("EmojiGetByName", func(t *testing.T) { testEmojiGetByName(t, ss) }) t.Run("EmojiGetList", func(t *testing.T) { testEmojiGetList(t, ss) }) + t.Run("EmojiSearch", func(t *testing.T) { testEmojiSearch(t, ss) }) } func testEmojiSaveDelete(t *testing.T, ss store.Store) { @@ -191,3 +192,70 @@ func testEmojiGetList(t *testing.T, ss store.Store) { assert.Equal(t, emojis[2].Name, remojis[1].Name) } + +func testEmojiSearch(t *testing.T, ss store.Store) { + emojis := []model.Emoji{ + { + CreatorId: model.NewId(), + Name: "blargh_" + model.NewId(), + }, + { + CreatorId: model.NewId(), + Name: model.NewId() + "_blargh", + }, + { + CreatorId: model.NewId(), + Name: model.NewId() + "_blargh_" + model.NewId(), + }, + { + CreatorId: model.NewId(), + Name: model.NewId(), + }, + } + + for i, emoji := range emojis { + emojis[i] = *store.Must(ss.Emoji().Save(&emoji)).(*model.Emoji) + } + defer func() { + for _, emoji := range emojis { + store.Must(ss.Emoji().Delete(emoji.Id, time.Now().Unix())) + } + }() + + shouldFind := []bool{true, false, false, false} + + if result := <-ss.Emoji().Search("blargh", true, 100); result.Err != nil { + t.Fatal(result.Err) + } else { + for i, emoji := range emojis { + found := false + + for _, savedEmoji := range result.Data.([]*model.Emoji) { + if emoji.Id == savedEmoji.Id { + found = true + break + } + } + + assert.Equal(t, shouldFind[i], found, emoji.Name) + } + } + + shouldFind = []bool{true, true, true, false} + if result := <-ss.Emoji().Search("blargh", false, 100); result.Err != nil { + t.Fatal(result.Err) + } else { + for i, emoji := range emojis { + found := false + + for _, savedEmoji := range result.Data.([]*model.Emoji) { + if emoji.Id == savedEmoji.Id { + found = true + break + } + } + + assert.Equal(t, shouldFind[i], found, emoji.Name) + } + } +} -- cgit v1.2.3-1-g7c22