Skip to content

Commit

Permalink
initial user groups controller specs
Browse files Browse the repository at this point in the history
  • Loading branch information
yuenmichelle1 committed Aug 3, 2023
1 parent a2be9cc commit 8ee0a9f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/controllers/user_group_classification_count_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ class UserGroupClassificationCountController < ApplicationController
# before_action :require_login

def query
# TODO: pundit policy for user groups, will probably look something like below, but for now, SKIP authorization
# TODO: Skipping Auth for now, Will introduce this in a separate PR
# pundit policy for user groups, will probably look something like below:
# current_user['queried_user_group_id'] = params[:id]
# authorize :queried_user_context, :show?
# authorize :queried_user_group_context, :show?
skip_authorization
if params[:individual_stats_breakdown]
# TODO: in a separate PR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe UserGroupClassificationCountController do
describe 'GET query' do
let!(:classification_user_group) { create(:classification_user_group) }

it 'returns total_count, time_spent, active_users, and project_contributions of user group' do
get :query, params: { id: classification_user_group.user_group_id.to_s }
expect(response.status).to eq(200)
response_body = JSON.parse(response.body)
expect(response_body['total_count']).to eq(1)
expect(response_body['time_spent']).to eq(classification_user_group.session_time)
expect(response_body['active_users']).to eq(1)
expect(response_body['project_contributions'].length).to eq(1)
end

it 'does not compute project_contributions when params[:project_id] given' do
get :query, params: { id: classification_user_group.user_group_id.to_s, project_id: 2 }
expect(response.status).to eq(200)
response_body = JSON.parse(response.body)
expect(response_body).not_to have_key(:project_contributions)
end

it 'does not compute project_contributions when params[:workflow_id] given' do
get :query, params: { id: classification_user_group.user_group_id.to_s, workflow_id: 2 }
expect(response.status).to eq(200)
response_body = JSON.parse(response.body)
expect(response_body).not_to have_key(:project_contributions)
end

context 'param validations' do
it_behaves_like 'ensure valid query params', :query, id: 1

it 'ensures you cannot query individual_stats_breakdown and any non date range param' do
get :query, params: { id: 1, individual_stats_breakdown: true, project_id: 1 }
expect(response.status).to eq(400)
expect(response.body).to include('Cannot query individual stats breakdown with anything else EXCEPT start_date and end_date')
end

it 'ensures individual_stats_breakdown is a boolean' do
get :query, params: { id: 1, individual_stats_breakdown: '100' }
expect(controller.params[:individual_stats_breakdown]).to eq(false)
end

it 'ensures individual_stats_breakdown is true if given string true' do
get :query, params: { id: 1, individual_stats_breakdown: 'true' }
expect(controller.params[:individual_stats_breakdown]).to eq(true)
end

it 'ensures top_contributors is an integer' do
get :query, params: { id: 1, top_contributors: '10' }
expect(controller.params[:top_contributors]).to eq(10)
end
end
end
end

0 comments on commit 8ee0a9f

Please sign in to comment.