From ad95f02b1654cdaa745e6c50618455c6108d2156 Mon Sep 17 00:00:00 2001 From: Sawy Date: Sun, 8 Sep 2024 21:59:45 +0300 Subject: [PATCH] CV2-5225: add tests --- test/controllers/elastic_search_7_test.rb | 24 +++++++++++++++++++ test/controllers/elastic_search_9_test.rb | 29 ++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/test/controllers/elastic_search_7_test.rb b/test/controllers/elastic_search_7_test.rb index dca282fad6..236c33c2bf 100644 --- a/test/controllers/elastic_search_7_test.rb +++ b/test/controllers/elastic_search_7_test.rb @@ -300,5 +300,29 @@ def setup end end + test "should ignore index task responses that exceeds nested objects limit" do + team = create_team + tt = create_team_task team_id: team.id, type: 'single_choice', options: ['ans_a', 'ans_b', 'ans_c'] + tt2 = create_team_task team_id: team.id, type: 'single_choice', options: ['ans_aa', 'ans_bb', 'ans_cc'] + tt3 = create_team_task team_id: team.id, type: 'single_choice', options: ['ans_aaa', 'ans_bbb', 'ans_ccc'] + pm = create_project_media team: team + stub_configs({ 'nested_objects_limit' => 2 }) do + # answer single choice + puts "Start to answer" + pm_tt = pm.annotations('task').select{|t| t.team_task_id == tt.id}.last + pm_tt.response = { annotation_type: 'task_response_single_choice', set_fields: { response_single_choice: 'ans_a' }.to_json }.to_json + pm_tt.save! + # pm_tt2 = pm.annotations('task').select{|t| t.team_task_id == tt2.id}.last + # pm_tt2.response = { annotation_type: 'task_response_single_choice', set_fields: { response_single_choice: 'ans_aa' }.to_json }.to_json + # pm_tt2.save! + # pm_tt3 = pm.annotations('task').select{|t| t.team_task_id == tt3.id}.last + # pm_tt3.response = { annotation_type: 'task_response_single_choice', set_fields: { response_single_choice: 'ans_aaa' }.to_json }.to_json + # pm_tt3.save! + sleep 2 + es = $repository.find(pm.get_es_doc_id) + pp es['task_responses'] + end + end + # Please add new tests to test/controllers/elastic_search_8_test.rb end diff --git a/test/controllers/elastic_search_9_test.rb b/test/controllers/elastic_search_9_test.rb index a015628a52..3f14d8f219 100644 --- a/test/controllers/elastic_search_9_test.rb +++ b/test/controllers/elastic_search_9_test.rb @@ -206,7 +206,7 @@ def setup test "shoud add team filter by default" do t = create_team t2 = create_team - pm1 = create_project_media team: t, quote: 'test', disable_es_callbacks: false + pm1 = create_project_media team: t, quote: 'test', disable_es_callbacks: false pm2 = create_project_media team: t2, quote: 'test', disable_es_callbacks: false ProjectMedia.where(id: [pm1.id, pm2.id]).update_all(project_id: nil) options = { @@ -230,5 +230,32 @@ def setup Team.unstub(:current) end + test "should ignore index document that exceeds nested objects limit" do + team = create_team + pm = create_project_media team: team + stub_configs({ 'nested_objects_limit' => 2 }) do + tr = create_tipline_request associated: pm, disable_es_callbacks: false + tr2 = create_tipline_request associated: pm, disable_es_callbacks: false + tr3 = create_tipline_request associated: pm, disable_es_callbacks: false + t = create_tag annotated: pm, disable_es_callbacks: false + t2 = create_tag annotated: pm, disable_es_callbacks: false + t3 = create_tag annotated: pm, disable_es_callbacks: false + c = create_comment annotated: pm, disable_es_callbacks: false + c2 = create_comment annotated: pm, disable_es_callbacks: false + c3 = create_comment annotated: pm, disable_es_callbacks: false + sleep 2 + es = $repository.find(pm.get_es_doc_id) + requests = es['requests'] + assert_equal 2, requests.size + assert_equal [tr.id, tr2.id], requests.collect{|r| r['id']}.sort + tags = es['tags'] + assert_equal 2, tags.size + assert_equal [t.id, t2.id], tags.collect{|i| i['id']}.sort + comments = es['comments'] + assert_equal 2, comments.size + assert_equal [c.id, c2.id], comments.collect{|i| i['id']}.sort + end + end + # Please add new tests to test/controllers/elastic_search_10_test.rb end