Skip to content

Commit

Permalink
test: added excluding anonymous posts test for build_course_stats
Browse files Browse the repository at this point in the history
  • Loading branch information
eemaanamir committed Nov 29, 2023
1 parent 2f80c3f commit 14a7184
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
23 changes: 23 additions & 0 deletions spec/api/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,29 @@ def get_new_stats
expect(new_stats["active_flags"]).to eq @original_stats["active_flags"] - 1
end
end
describe "build_course_stats" do
let(:user) { create_test_user 3}
let(:course_id) { DFLT_COURSE_ID }

context 'when the user has made anonymous posts' do
before do
make_anonymous_to_peers_thread(user, "anon thread 1 by author", DFLT_COURSE_ID, "anon_thread_1")
make_anonymous_thread(user, "anon thread 2 by author", DFLT_COURSE_ID, "anon_thread_2")
end

it 'does not include anonymous posts in the counts after making a non-anonymous post' do

make_thread(user, "thread by new author #{user}", DFLT_COURSE_ID, "new_thread")

get "/api/v1/users/#{course_id}/stats"
expect(last_response.status).to eq(200)
stats = parse(last_response.body)
expect(stats["user_stats"][0]["replies"]).to eq(0)
expect(stats["user_stats"][0]["responses"]).to eq(0)
expect(stats["user_stats"][0]["threads"]).to eq(1)
end
end
end
end

describe "POST /api/v1/users/:course_id/update_stats" do
Expand Down
18 changes: 18 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,24 @@ def make_thread(author, text, course_id, commentable_id, thread_type=:discussion
thread
end

def make_anonymous_to_peers_thread(author, text, course_id, commentable_id, thread_type=:discussion, context=:course)
thread = CommentThread.new(title: text, body: text, course_id: course_id, commentable_id: commentable_id, anonymous_to_peers: true)
thread.thread_type = thread_type
thread.author = author
thread.context = context
thread.save!
thread
end

def make_anonymous_thread(author, text, course_id, commentable_id, thread_type=:discussion, context=:course)
thread = CommentThread.new(title: text, body: text, course_id: course_id, commentable_id: commentable_id, anonymous: true)
thread.thread_type = thread_type
thread.author = author
thread.context = context
thread.save!
thread
end

def make_comment(author, parent, text)
if parent.is_a?(CommentThread)
coll = parent.comments
Expand Down

0 comments on commit 14a7184

Please sign in to comment.