Skip to content

Commit

Permalink
Update user classification counts filtering by project if session tim…
Browse files Browse the repository at this point in the history
…e is false. do not return session time as key in response (#36)

* update user classification counts so that if show_time_spent is false when filtering user classification counts by project, session_time is not returned as a key

* update user_classification_counts serializer to not display sesion_time calculation if time_spent is false (and when not project_contributions=true)
  • Loading branch information
yuenmichelle1 authored Oct 2, 2023
1 parent 966d6d8 commit 6198953
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/serializers/user_classification_counts_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ def response_data(user_counts, show_project_contributions:, show_time_spent:)
end
counts_grouped_by_period.map { |period, totals| { period: }.merge(totals) }
else
user_counts
user_counts.map do |c|
period_data = {
period: c.period,
count: c.count
}
show_time_spent ? period_data.merge({ session_time: c.session_time }) : period_data
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
expect(response_body['data'][0]['count']).to eq(1)
end

it 'returns total_count and time_spent and breakdown of user classifications wher period is given' do
it 'returns total_count and time_spent and breakdown of user classifications where period is given' do
get :query, params: { id: classification_event.user_id, period: 'day', time_spent: true }
expect(response.status).to eq(200)
response_body = JSON.parse(response.body)
Expand All @@ -47,6 +47,13 @@
expect(response_body['project_contributions'].length).to eq(1)
expect(response_body['project_contributions'][0]['project_id']).to eq(classification_event.project_id)
end

it 'returns user project classification counts without session_time if time_spent is false' do
get :query, params: { id: classification_event.user_id, project_id: 1, period: 'day' }
expect(response.status).to eq(200)
response_body = JSON.parse(response.body)
expect(response_body['data'][0]).not_to have_key('session_time')
end
end

context 'zooniverse_admin' do
Expand Down

0 comments on commit 6198953

Please sign in to comment.