-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathskill_controller_search_test.exs
59 lines (49 loc) · 2.25 KB
/
skill_controller_search_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
defmodule SkillControllerSearchIntegrationTest do
use ExUnit.Case, async: true
alias CodeCorps.ElasticSearchHelper
@test_url Application.get_env(:code_corps, :elasticsearch_url)
@test_index "skills"
@type_value "title"
@elixir %{"id" => 1, "description" => "Elixir is an awesome functional language", "title" => "Elixir", "original_row" => 1}
@ruby %{"id" => 2, "description" => "Ruby is an awesome OO language", "title" => "Ruby", "original_row" => 2}
@rails %{"id" => 3, "description" => "Rails is a modern framework", "title" => "Rails", "original_row" => 3}
@css %{"id" => 4, "description" => "CSS is pretty cool too", "title" => "CSS", "original_row" => 4}
@phoenix %{"id" => 5, "description" => "Phoenix is a super framework", "title" => "Phoenix", "original_row" => 5}
setup do
ElasticSearchHelper.delete(@test_url, @test_index)
ElasticSearchHelper.create_index(@test_url, @test_index, @type_value)
init()
:ok
end
test "search partial word" do
results = ElasticSearchHelper.search(@test_url, @test_index, "title", "ru")
assert results == [@ruby]
end
test "fuzzy search partial word" do
results = ElasticSearchHelper.search(@test_url, @test_index, "title", "rj")
# Two lists can be concatenated or subtracted using the ++/2 and --/2
# see: http://elixir-lang.org/getting-started/basic-types.html#linked-lists
# This allows us to confirm the values we want regardless of the order the values are returned in.
assert results -- ["Ruby", "Rails"] == []
end
test "search whole word" do
results = ElasticSearchHelper.search(@test_url, @test_index, "title", "css")
assert results == [@css]
end
test "fuzzy search whole word" do
results = ElasticSearchHelper.search(@test_url, @test_index, "title", "csw")
assert results == [@css]
end
test "search no matches" do
results = ElasticSearchHelper.search(@test_url, @test_index, "title", "foo")
assert results == []
end
test "match all entries" do
results = ElasticSearchHelper.match_all(@test_url, @test_index, "title")
assert results -- [@elixir, @ruby, @rails, @css] == []
end
def init do
ElasticSearchHelper.add_documents(@test_url, @test_index, @type_value,
[@elixir, @css, @ruby], [refresh: true])
end
end