Commit abc8ae0cf06d61db5b697a31abb235ed31bf024a
1 parent
c9ef2a43
Adds categories tests for the api
Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Showing
1 changed file
with
13 additions
and
1 deletions
Show diff stats
plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb
| @@ -11,8 +11,13 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | @@ -11,8 +11,13 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | ||
| 11 | end | 11 | end |
| 12 | 12 | ||
| 13 | def create_instances | 13 | def create_instances |
| 14 | + 5.times.each {|index| fast_create Category, name: "category#{index}", id: index+1 } | ||
| 14 | 7.times.each {|index| create_user "person #{index}"} | 15 | 7.times.each {|index| create_user "person #{index}"} |
| 15 | - 4.times.each {|index| fast_create Community, name: "community #{index}" } | 16 | + 4.times.each do |index| |
| 17 | + community = fast_create Community, name: "community #{index}" | ||
| 18 | + community.categories.push Category.find(index+1) | ||
| 19 | + community.save | ||
| 20 | + end | ||
| 16 | end | 21 | end |
| 17 | 22 | ||
| 18 | should 'show all types avaliable in /search/types endpoint' do | 23 | should 'show all types avaliable in /search/types endpoint' do |
| @@ -49,4 +54,11 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | @@ -49,4 +54,11 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | ||
| 49 | assert_equal 200, last_response.status | 54 | assert_equal 200, last_response.status |
| 50 | assert_equal 4, json["results"].count | 55 | assert_equal 4, json["results"].count |
| 51 | end | 56 | end |
| 57 | + | ||
| 58 | + should 'respond with only the correct categories' do | ||
| 59 | + get "/api/v1/search?categories=1,2,3" | ||
| 60 | + json = JSON.parse(last_response.body) | ||
| 61 | + assert_equal 200, last_response.status | ||
| 62 | + assert_equal 3, json["results"].count | ||
| 63 | + end | ||
| 52 | end | 64 | end |