Skip to content

Commit

Permalink
CV2-5225: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy committed Sep 8, 2024
1 parent 763e51c commit ad95f02
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
24 changes: 24 additions & 0 deletions test/controllers/elastic_search_7_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 28 additions & 1 deletion test/controllers/elastic_search_9_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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

0 comments on commit ad95f02

Please sign in to comment.