Skip to content

Commit

Permalink
test: fixed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ayesha-waris committed Feb 29, 2024
1 parent d18653c commit db49135
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
9 changes: 8 additions & 1 deletion spec/api/comment_thread_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,14 @@ def thread_result(id, params)
it "limits responses when no skip/limit params given" do
@threads.each do |n, thread|
res = thread_result thread.id, {}
check_thread_response_paging_json thread, res, 0, nil, false
check_thread_response_paging_json thread, res, 0, nil, false, false
end
end

it "handles responses when merge_question_type_responses param is given" do
@threads.each do |n, thread|
res = thread_result thread.id, {}
check_thread_response_paging_json thread, res, 0, nil, false, true
end
end

Expand Down
11 changes: 10 additions & 1 deletion spec/presenters/thread_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe ThreadPresenter do

context "#to_hash" do
let(:default_resp_limit) { CommentService.config["thread_response_default_size"] }

Expand Down Expand Up @@ -167,6 +167,15 @@ def random_flag_abuses!(comment)
end
end

it "handles merge_question_type_responses=true" do
@threads_with_num_comments.each do |thread, num_comments|
is_endorsed = num_comments > 0 && endorse_responses
hash = ThreadPresenter.new(thread, @reader, false, num_comments, is_endorsed, nil).to_hash(true, 0, default_resp_limit, true, false, true, true)
check_thread_result(@reader, thread, hash)
check_thread_response_paging(thread, hash, 0, default_resp_limit, false, false, true, true)
end
end

it "handles reversed_order and recursive with skip and limit" do
@threads_with_num_comments.each do |thread, num_comments|
is_endorsed = num_comments > 0 && endorse_responses
Expand Down
16 changes: 8 additions & 8 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ def check_unread_thread_result_json(thread, json_response)
check_thread_result(nil, thread, json_response, true)
end

def check_thread_response_paging(thread, hash, resp_skip=0, resp_limit=nil, is_json=false, recursive=false, reverse_order=false)
case thread.thread_type
when "discussion"
check_discussion_response_paging(thread, hash, resp_skip, resp_limit, is_json, recursive, reverse_order)
when "question"
check_question_response_paging(thread, hash, resp_skip, resp_limit, is_json, recursive, reverse_order)
def check_thread_response_paging(thread, hash, resp_skip=0, resp_limit=nil, is_json=false, recursive=false, reverse_order=false, merge_question_type_responses=false)

if (thread.thread_type == "discussion" || (thread.thread_type == "question" && merge_question_type_responses))
check_discussion_response_paging(thread, hash, resp_skip, resp_limit, is_json, recursive, reverse_order)
else
check_question_response_paging(thread, hash, resp_skip, resp_limit, is_json, recursive, reverse_order)
end
end

Expand Down Expand Up @@ -333,8 +333,8 @@ def check_question_response_paging(thread, hash, resp_skip=0, resp_limit=nil, is
end
end

def check_thread_response_paging_json(thread, hash, resp_skip=0, resp_limit=nil, recursive=false, reverse_order=false)
check_thread_response_paging(thread, hash, resp_skip, resp_limit, true, recursive, reverse_order)
def check_thread_response_paging_json(thread, hash, resp_skip=0, resp_limit=nil, recursive=false, reverse_order=false, merge_question_type_responses=false)
check_thread_response_paging(thread, hash, resp_skip, resp_limit, true, recursive, reverse_order, merge_question_type_responses)
end

# general purpose factory helpers
Expand Down

0 comments on commit db49135

Please sign in to comment.