Commit 52b40cf4 by wajeeha-khalid

MA-1359 returned resp_total for existing question and new thread

parent 2e84f826
...@@ -47,6 +47,8 @@ post "#{APIPREFIX}/:commentable_id/threads" do |commentable_id| ...@@ -47,6 +47,8 @@ post "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
else else
user.subscribe(thread) if bool_auto_subscribe user.subscribe(thread) if bool_auto_subscribe
presenter = ThreadPresenter.factory(thread, nil) presenter = ThreadPresenter.factory(thread, nil)
presenter.to_hash.to_json thread = presenter.to_hash
thread["resp_total"] = 0
thread.to_json
end end
end end
...@@ -51,6 +51,7 @@ class ThreadPresenter ...@@ -51,6 +51,7 @@ class ThreadPresenter
h["endorsed_responses"] = endorsed_response_info["responses"] h["endorsed_responses"] = endorsed_response_info["responses"]
h["non_endorsed_responses"] = non_endorsed_response_info["responses"] h["non_endorsed_responses"] = non_endorsed_response_info["responses"]
h["non_endorsed_resp_total"] = non_endorsed_response_info["response_count"] h["non_endorsed_resp_total"] = non_endorsed_response_info["response_count"]
h["resp_total"] = non_endorsed_response_info["response_count"] + endorsed_response_info["response_count"]
when "discussion" when "discussion"
response_info = get_paged_merged_responses(@thread._id, responses, resp_skip, resp_limit) response_info = get_paged_merged_responses(@thread._id, responses, resp_skip, resp_limit)
h["children"] = response_info["responses"] h["children"] = response_info["responses"]
......
...@@ -102,6 +102,7 @@ describe "app" do ...@@ -102,6 +102,7 @@ describe "app" do
result["read"].should == false result["read"].should == false
result["unread_comments_count"].should == 0 result["unread_comments_count"].should == 0
result["endorsed"].should == false result["endorsed"].should == false
result["resp_total"].should == 0
CommentThread.count.should == old_count + 1 CommentThread.count.should == old_count + 1
thread = CommentThread.where(title: "Interesting question").first thread = CommentThread.where(title: "Interesting question").first
thread.should_not be_nil thread.should_not be_nil
......
...@@ -341,6 +341,9 @@ def check_question_response_paging(thread, hash, resp_skip=0, resp_limit=nil, is ...@@ -341,6 +341,9 @@ def check_question_response_paging(thread, hash, resp_skip=0, resp_limit=nil, is
hash["non_endorsed_responses"].each_with_index do |response_hash, i| hash["non_endorsed_responses"].each_with_index do |response_hash, i|
check_comment(expected_non_endorsed_responses[i], response_hash, is_json) check_comment(expected_non_endorsed_responses[i], response_hash, is_json)
end end
total_responses = endorsed_responses.length + non_endorsed_responses.length
hash["resp_total"].should == total_responses
hash["resp_skip"].to_i.should == resp_skip hash["resp_skip"].to_i.should == resp_skip
if resp_limit.nil? if resp_limit.nil?
hash["resp_limit"].should be_nil hash["resp_limit"].should be_nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment