diff --git a/app/serializers/user_classification_counts_serializer.rb b/app/serializers/user_classification_counts_serializer.rb index b786c67..ff92905 100644 --- a/app/serializers/user_classification_counts_serializer.rb +++ b/app/serializers/user_classification_counts_serializer.rb @@ -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 diff --git a/spec/controllers/user_classification_count_controller_spec.rb b/spec/controllers/user_classification_count_controller_spec.rb index d8e754e..1d7b57b 100644 --- a/spec/controllers/user_classification_count_controller_spec.rb +++ b/spec/controllers/user_classification_count_controller_spec.rb @@ -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) @@ -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