Skip to content

Commit

Permalink
adding specs
Browse files Browse the repository at this point in the history
  • Loading branch information
yuenmichelle1 committed Oct 18, 2024
1 parent 2796462 commit 28891e3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
18 changes: 18 additions & 0 deletions spec/controllers/user_classification_count_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@
get :query, params: { id: 1, time_spent: 'true' }
expect(controller.params[:time_spent]).to eq(true)
end

context 'order_project_contributions validations' do
it 'errors if not a valid order_project_contributions_by option' do
get :query, params: { id: 1, order_project_contributions_by: 'blank' }
expect(response.status).to eq(400)
expect(response.body).to include('Can only order project contributions by recents or count')
end

it 'allows allowable order_project_contributions_by option' do
get :query, params: { id: 1, order_project_contributions_by: 'recents' }
expect(response.status).to eq(200)
end

it 'allows order_project_contributions_by to be case-insensitive' do
get :query, params: { id: 1, order_project_contributions_by: 'COUNT' }
expect(response.status).to eq(200)
end
end
end
end
end
26 changes: 24 additions & 2 deletions spec/serializers/user_classification_counts_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
let(:user_diff_period_classification_count) { build(:user_diff_period_classification_count) }
let(:serializer) { described_class.new([user_diff_period_classification_count, user_classification_count, user_diff_proj_count]) }

it 'shows project_contributions ordered desc by count' do
it 'shows project_contributions ordered desc by count when order_proj_contribution_by by not given' do
serialized = serializer.as_json(serializer_options: { project_contributions: true })
expect(serialized[:project_contributions].length).to eq(2)
expect(serialized[:project_contributions][0][:project_id]).to eq(user_classification_count.project_id)
Expand All @@ -68,7 +68,29 @@
expect(serialized[:project_contributions][1][:count]).to eq(user_diff_proj_count.count)
end

it 'shows response data bucketed by period when querying top_projects' do
context 'when order_project_contributions_by param is given' do
it 'shows project_contributions ordered desc by count when order_proj_contribution_by is count' do
serialized = serializer.as_json(serializer_options: { project_contributions: true, order_project_contributions_by: 'count' })
expect(serialized[:project_contributions].length).to eq(2)
expect(serialized[:project_contributions][0][:project_id]).to eq(user_classification_count.project_id)
expect(serialized[:project_contributions][0][:count]).to eq(user_classification_count.count + user_diff_period_classification_count.count)
expect(serialized[:project_contributions][1][:project_id]).to eq(user_diff_proj_count.project_id)
expect(serialized[:project_contributions][1][:count]).to eq(user_diff_proj_count.count)
end

it 'shows project_contributions ordered by recents when order_proj_contribution_by is recents' do
classification_count_diff_project_created_yesterday = build(:user_diff_proj_classification_count, period: Date.today - 1)
serializer = described_class.new([classification_count_diff_project_created_yesterday,user_classification_count])
serialized = serializer.as_json(serializer_options: { project_contributions: true, order_project_contributions_by: 'recents' })
expect(serialized[:project_contributions].length).to eq(2)
expect(serialized[:project_contributions][0][:project_id]).to eq(user_classification_count.project_id)
expect(serialized[:project_contributions][0][:count]).to eq(user_classification_count.count)
expect(serialized[:project_contributions][1][:project_id]).to eq(classification_count_diff_project_created_yesterday.project_id)
expect(serialized[:project_contributions][1][:count]).to eq(classification_count_diff_project_created_yesterday.count)
end
end

it 'shows response data bucketed by period when querying project_contributions by count' do
serialized = serializer.as_json(serializer_options: { project_contributions: true, period: 'day' })
expect(serialized[:data].length).to eq(2)
expect(serialized[:data][0][:period]).to eq(user_diff_period_classification_count.period)
Expand Down

0 comments on commit 28891e3

Please sign in to comment.