Skip to content

Commit

Permalink
update user_classification_counts serializer to not display sesion_ti…
Browse files Browse the repository at this point in the history
…me calculation if time_spent is false (and when not project_contributions=true)
  • Loading branch information
yuenmichelle1 committed Oct 2, 2023
1 parent 97935b1 commit 7080faa
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 7080faa

Please sign in to comment.