diff --git a/plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb b/plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb index a7d1e05..f468aac 100644 --- a/plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb +++ b/plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb @@ -7,7 +7,53 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase include ElasticsearchHelper def indexed_models - [Community, Person] + [Person,TextArticle,UploadedFile,Community,Event] + end + + def create_instances + create_instances_environment + create_instances_environment2 + end + + def create_instances_environment2 + create_user "Sample User Environment 2", environment:Environment.second + fast_create Community, name:"Sample Community Environment 2", created_at: Date.new, environment_id: Environment.second.id + end + + def create_instances_environment + create_visible_models + create_private_models + end + + def create_visible_models + 7.times{ | index | create_user "person #{index}" } + 4.times{ | index | fast_create Community, name: "community #{index}", created_at: Date.new } + end + + def create_private_models + secret_user = create_user("Secret Person") + fast_update(secret_user.person, secret: true, visible: true) + + invisible_user= create_user("Invisible Person") + fast_update(invisible_user.person, secret: false, visible: false, public_profile: false) + + fast_create(Community, name: "secret community", secret: true, visible: true) + fast_create(Community, name: "invisible community", secret: false, visible: false) + + create_private_article(TextArticle,public_person: User.first.person, private_person: invisible_user.person) + create_private_article(UploadedFile,public_person: User.first.person, private_person: invisible_user.person) + create_private_article(Event,public_person: User.first.person, private_person: invisible_user.person) + + end + + def create_private_article model,options = {} + public_person = options[:public_person] + private_person = options[:private_person] + + fast_create(model, name: "#{model.to_s.underscore} not advertise", advertise: false, published: true, profile_id: public_person, created_at: Time.now) + fast_create(model, name: "#{model.to_s.underscore} not published", advertise: true, published: false, profile_id: public_person, created_at: Time.now) + fast_create(model, name: "#{model.to_s.underscore} with not visible profile", advertise: true, published: true, profile_id: private_person, created_at: Time.now) + fast_create(model, name: "#{model.to_s.underscore} with not public_profile", advertise: true, published: true, profile_id: private_person, created_at: Time.now) end def create_instances @@ -49,4 +95,19 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase assert_equal 200, last_response.status assert_equal 4, json["results"].count end + + should 'filter person by default environment' do + get "/api/v1/search?selected_type=person" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal 7, json["results"].count + end + + should 'not show private text_article' do + get "/api/v1/search?selected_type=text_article" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal 7, json["results"].count + end + end -- libgit2 0.21.2