Commit 1110c0124def61533d8a0631fb589ee00eaedbba
Committed by
Macartur Sousa
1 parent
cebb76c4
Exists in
staging
and in
6 other branches
Elasticsearch: Adds tests for the category
* Adds filter tests for controller * Adds categories tests for the api Signed-off-by: DylanGuedes <djmgguedes@gmail.com> Signed-off-by: Macartur de Sousa <macartur.sc@gmail.com>
Showing
2 changed files
with
30 additions
and
4 deletions
Show diff stats
plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb
| @@ -57,8 +57,13 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | @@ -57,8 +57,13 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | ||
| 57 | end | 57 | end |
| 58 | 58 | ||
| 59 | def create_instances | 59 | def create_instances |
| 60 | + 5.times.each {|index| fast_create Category, name: "category#{index}", id: index+1 } | ||
| 60 | 7.times.each {|index| create_user "person #{index}"} | 61 | 7.times.each {|index| create_user "person #{index}"} |
| 61 | - 4.times.each {|index| fast_create Community, name: "community #{index}" } | 62 | + 4.times.each do |index| |
| 63 | + community = fast_create Community, name: "community #{index}" | ||
| 64 | + community.categories.push Category.find(index+1) | ||
| 65 | + community.save | ||
| 66 | + end | ||
| 62 | end | 67 | end |
| 63 | 68 | ||
| 64 | should 'show all types avaliable in /search/types endpoint' do | 69 | should 'show all types avaliable in /search/types endpoint' do |
| @@ -110,4 +115,11 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | @@ -110,4 +115,11 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | ||
| 110 | assert_equal 7, json["results"].count | 115 | assert_equal 7, json["results"].count |
| 111 | end | 116 | end |
| 112 | 117 | ||
| 118 | + should 'respond with only the correct categories' do | ||
| 119 | + get "/api/v1/search?categories=1,2,3" | ||
| 120 | + json = JSON.parse(last_response.body) | ||
| 121 | + assert_equal 200, last_response.status | ||
| 122 | + assert_equal 3, json["results"].count | ||
| 123 | + end | ||
| 124 | + | ||
| 113 | end | 125 | end |
plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb
| @@ -24,11 +24,18 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -24,11 +24,18 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
| 24 | end | 24 | end |
| 25 | 25 | ||
| 26 | def create_visible_models | 26 | def create_visible_models |
| 27 | + categories = [] | ||
| 27 | 5.times do | index | | 28 | 5.times do | index | |
| 29 | + categories[index] = fast_create Category, name: "Category#{index}", id: index+1 | ||
| 28 | create_user "person #{index}" | 30 | create_user "person #{index}" |
| 29 | end | 31 | end |
| 32 | + | ||
| 30 | 6.times do | index | | 33 | 6.times do | index | |
| 31 | - fast_create Community, name: "community #{index}", created_at: Date.new | 34 | + community = fast_create Community, name: "community #{index}", created_at: Date.new |
| 35 | + if categories[index] | ||
| 36 | + community.categories.push categories[index] | ||
| 37 | + community.save | ||
| 38 | + end | ||
| 32 | end | 39 | end |
| 33 | end | 40 | end |
| 34 | 41 | ||
| @@ -45,7 +52,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -45,7 +52,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
| 45 | create_private_article(TextArticle,public_person: User.first.person, private_person: invisible_user.person) | 52 | create_private_article(TextArticle,public_person: User.first.person, private_person: invisible_user.person) |
| 46 | create_private_article(UploadedFile,public_person: User.first.person, private_person: invisible_user.person) | 53 | create_private_article(UploadedFile,public_person: User.first.person, private_person: invisible_user.person) |
| 47 | create_private_article(Event,public_person: User.first.person, private_person: invisible_user.person) | 54 | create_private_article(Event,public_person: User.first.person, private_person: invisible_user.person) |
| 48 | - | ||
| 49 | end | 55 | end |
| 50 | 56 | ||
| 51 | def create_private_article model,options = {} | 57 | def create_private_article model,options = {} |
| @@ -142,7 +148,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -142,7 +148,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
| 142 | assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params | 148 | assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params |
| 143 | end | 149 | end |
| 144 | 150 | ||
| 145 | - | ||
| 146 | should 'filter community by default environment' do | 151 | should 'filter community by default environment' do |
| 147 | get :index, { "selected_type" => :community} | 152 | get :index, { "selected_type" => :community} |
| 148 | assert_response :success | 153 | assert_response :success |
| @@ -173,4 +178,13 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -173,4 +178,13 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
| 173 | assert_select ".search-item", 0 | 178 | assert_select ".search-item", 0 |
| 174 | end | 179 | end |
| 175 | 180 | ||
| 181 | + should 'filter by selected categories' do | ||
| 182 | + get :index, { "categories" => "1,2,3" } | ||
| 183 | + assert_response :success | ||
| 184 | + assert_select ".search-item", 3 | ||
| 185 | + get :index, { "categories" => "5" } | ||
| 186 | + assert_response :success | ||
| 187 | + assert_select ".search-item", 1 | ||
| 188 | + end | ||
| 189 | + | ||
| 176 | end | 190 | end |