-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: 500 error if paginated_stats are empty #422
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #422 +/- ##
=======================================
Coverage 96.14% 96.15%
=======================================
Files 58 58
Lines 4562 4573 +11
=======================================
+ Hits 4386 4397 +11
Misses 176 176 ☔ View full report in Codecov by Sentry. |
f94ffaa
to
ceb9dc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a little refactor. otherwise, LGTM
api/users.rb
Outdated
if paginated_stats["pagination"].empty? | ||
data = [] | ||
num_pages = 0 | ||
page = 0 | ||
total_count = 0 | ||
else | ||
total_count = paginated_stats["pagination"][0]["total_count"] | ||
num_pages = [1, (total_count / per_page.to_f).ceil].max | ||
data = paginated_stats["data"].map do |user_stats| | ||
{ | ||
:username => user_stats["username"] | ||
}.merge(user_stats["course_stats"].except(*exclude_from_stats)) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if paginated_stats["pagination"].empty? | |
data = [] | |
num_pages = 0 | |
page = 0 | |
total_count = 0 | |
else | |
total_count = paginated_stats["pagination"][0]["total_count"] | |
num_pages = [1, (total_count / per_page.to_f).ceil].max | |
data = paginated_stats["data"].map do |user_stats| | |
{ | |
:username => user_stats["username"] | |
}.merge(user_stats["course_stats"].except(*exclude_from_stats)) | |
end | |
data = [] | |
num_pages = 0 | |
page = 0 | |
total_count = 0 | |
if not paginated_stats["pagination"].empty? | |
total_count = paginated_stats["pagination"][0]["total_count"] | |
num_pages = [1, (total_count / per_page.to_f).ceil].max | |
data = paginated_stats["data"].map do |user_stats| | |
{ | |
:username => user_stats["username"] | |
}.merge(user_stats["course_stats"].except(*exclude_from_stats)) | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Just a nit, LGTM! |
spec/api/user_spec.rb
Outdated
@@ -521,6 +521,14 @@ def build_structure_and_response(course_id, authors, build_initial_stats = true, | |||
expect(res["user_stats"]).to eq expected_result | |||
end | |||
|
|||
it "API doesn't fail if user has no activity" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename test to something like "handle stats for user with no activity"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
ceb9dc1
to
cae4f29
Compare
API was returning 500 when there were no stats in a course.
Ticket Link: INF-1067