From 6198953410cecd9f0bc888bd9c92e15fe4c63390 Mon Sep 17 00:00:00 2001 From: yuenmichelle1 Date: Mon, 2 Oct 2023 15:25:16 -0500 Subject: [PATCH] Update user classification counts filtering by project if session time 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) --- app/serializers/user_classification_counts_serializer.rb | 8 +++++++- .../user_classification_count_controller_spec.rb | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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