|
1 | 1 | defmodule SkillControllerSearchIntegrationTest do |
2 | 2 | use ExUnit.Case, async: true |
3 | 3 | alias CodeCorps.ElasticSearchHelper |
| 4 | + alias Elastix.Document |
4 | 5 |
|
5 | 6 | @test_url Application.get_env(:code_corps, :elasticsearch_url) |
6 | 7 | @test_index Application.get_env(:code_corps, :elasticsearch_index) |
| 8 | + @type_value "title" |
7 | 9 |
|
8 | 10 | setup do |
9 | | - Elastix.Index.delete(Application.get_env(:code_corps, :elasticsearch_url), |
10 | | - Application.get_env(:code_corps, :elasticsearch_index)) |
| 11 | + ElasticSearchHelper.delete(@test_url, @test_index) |
| 12 | + ElasticSearchHelper.create_index(@test_url, @test_index, @type_value) |
| 13 | + init() |
11 | 14 | :ok |
12 | 15 | end |
13 | 16 |
|
14 | 17 | test "search partial word" do |
15 | | - results = ElasticSearchHelper.search("ru") |
| 18 | + results = ElasticSearchHelper.search(@test_url, @test_index, "ru") |
16 | 19 | assert results == ["Ruby"] |
17 | 20 | end |
18 | 21 |
|
19 | 22 | test "search whole word" do |
20 | | - results = ElasticSearchHelper.search("css") |
| 23 | + results = ElasticSearchHelper.search(@test_url, @test_index, "css") |
21 | 24 | assert results == ["CSS"] |
22 | 25 | end |
23 | 26 |
|
24 | 27 | test "search no matches" do |
25 | | - results = ElasticSearchHelper.search("foo") |
| 28 | + results = ElasticSearchHelper.search(@test_url, @test_index, "foo") |
26 | 29 | assert results == [] |
27 | 30 | end |
28 | 31 |
|
| 32 | + def init do |
| 33 | + data = %{ |
| 34 | + title: "Elixir" |
| 35 | + } |
| 36 | + Document.index @test_url, @test_index, @type_value, 1, data, [refresh: true] |
| 37 | + data = %{ |
| 38 | + title: "Ruby" |
| 39 | + } |
| 40 | + Document.index @test_url, @test_index, @type_value, 2, data, [refresh: true] |
| 41 | + data = %{ |
| 42 | + title: "Rails" |
| 43 | + } |
| 44 | + Document.index @test_url, @test_index, @type_value, 3, data, [refresh: true] |
| 45 | + data = %{ |
| 46 | + title: "CSS" |
| 47 | + } |
| 48 | + Document.index @test_url, @test_index, @type_value, 4, data, [refresh: true] |
| 49 | + end |
29 | 50 | end |
0 commit comments