Commit 444ed76849c161f31db7e58eb563cecabe9a472b
1 parent
e1d27af8
Exists in
elasticsearch_filter
and in
1 other branch
Adding filter tests to api
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
1 changed file
with
62 additions
and
1 deletions
Show diff stats
plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb
@@ -7,7 +7,53 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | @@ -7,7 +7,53 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | ||
7 | include ElasticsearchHelper | 7 | include ElasticsearchHelper |
8 | 8 | ||
9 | def indexed_models | 9 | def indexed_models |
10 | - [Community, Person] | 10 | + [Person,TextArticle,UploadedFile,Community,Event] |
11 | + end | ||
12 | + | ||
13 | + def create_instances | ||
14 | + create_instances_environment | ||
15 | + create_instances_environment2 | ||
16 | + end | ||
17 | + | ||
18 | + def create_instances_environment2 | ||
19 | + create_user "Sample User Environment 2", environment:Environment.second | ||
20 | + fast_create Community, name:"Sample Community Environment 2", created_at: Date.new, environment_id: Environment.second.id | ||
21 | + end | ||
22 | + | ||
23 | + def create_instances_environment | ||
24 | + create_visible_models | ||
25 | + create_private_models | ||
26 | + end | ||
27 | + | ||
28 | + def create_visible_models | ||
29 | + 7.times{ | index | create_user "person #{index}" } | ||
30 | + 4.times{ | index | fast_create Community, name: "community #{index}", created_at: Date.new } | ||
31 | + end | ||
32 | + | ||
33 | + def create_private_models | ||
34 | + secret_user = create_user("Secret Person") | ||
35 | + fast_update(secret_user.person, secret: true, visible: true) | ||
36 | + | ||
37 | + invisible_user= create_user("Invisible Person") | ||
38 | + fast_update(invisible_user.person, secret: false, visible: false, public_profile: false) | ||
39 | + | ||
40 | + fast_create(Community, name: "secret community", secret: true, visible: true) | ||
41 | + fast_create(Community, name: "invisible community", secret: false, visible: false) | ||
42 | + | ||
43 | + create_private_article(TextArticle,public_person: User.first.person, private_person: invisible_user.person) | ||
44 | + create_private_article(UploadedFile,public_person: User.first.person, private_person: invisible_user.person) | ||
45 | + create_private_article(Event,public_person: User.first.person, private_person: invisible_user.person) | ||
46 | + | ||
47 | + end | ||
48 | + | ||
49 | + def create_private_article model,options = {} | ||
50 | + public_person = options[:public_person] | ||
51 | + private_person = options[:private_person] | ||
52 | + | ||
53 | + fast_create(model, name: "#{model.to_s.underscore} not advertise", advertise: false, published: true, profile_id: public_person, created_at: Time.now) | ||
54 | + fast_create(model, name: "#{model.to_s.underscore} not published", advertise: true, published: false, profile_id: public_person, created_at: Time.now) | ||
55 | + fast_create(model, name: "#{model.to_s.underscore} with not visible profile", advertise: true, published: true, profile_id: private_person, created_at: Time.now) | ||
56 | + fast_create(model, name: "#{model.to_s.underscore} with not public_profile", advertise: true, published: true, profile_id: private_person, created_at: Time.now) | ||
11 | end | 57 | end |
12 | 58 | ||
13 | def create_instances | 59 | def create_instances |
@@ -49,4 +95,19 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | @@ -49,4 +95,19 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase | ||
49 | assert_equal 200, last_response.status | 95 | assert_equal 200, last_response.status |
50 | assert_equal 4, json["results"].count | 96 | assert_equal 4, json["results"].count |
51 | end | 97 | end |
98 | + | ||
99 | + should 'filter person by default environment' do | ||
100 | + get "/api/v1/search?selected_type=person" | ||
101 | + json = JSON.parse(last_response.body) | ||
102 | + assert_equal 200, last_response.status | ||
103 | + assert_equal 7, json["results"].count | ||
104 | + end | ||
105 | + | ||
106 | + should 'not show private text_article' do | ||
107 | + get "/api/v1/search?selected_type=text_article" | ||
108 | + json = JSON.parse(last_response.body) | ||
109 | + assert_equal 200, last_response.status | ||
110 | + assert_equal 7, json["results"].count | ||
111 | + end | ||
112 | + | ||
52 | end | 113 | end |