Add test for case where student response rate does not meet threshold

pull/1/head
rebuilt 3 years ago
parent 62b6503816
commit da2e27e863

@ -18,6 +18,8 @@ describe ResponseRateCalculator, type: :model do
let(:insufficient_student_survey_item_1) { create(:student_survey_item, scale: sufficient_scale_1) } let(:insufficient_student_survey_item_1) { create(:student_survey_item, scale: sufficient_scale_1) }
let(:sufficient_student_survey_item_2) { create(:student_survey_item, scale: sufficient_scale_2) } let(:sufficient_student_survey_item_2) { create(:student_survey_item, scale: sufficient_scale_2) }
context 'when a students take a regular survey' do
context 'when the average number of student responses per question in a subcategory is equal to the student response threshold' do
before :each do before :each do
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item, create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item,
academic_year:, school:, likert_score: 1) academic_year:, school:, likert_score: 1)
@ -25,24 +27,43 @@ describe ResponseRateCalculator, type: :model do
academic_year:, school:, likert_score: 4) academic_year:, school:, likert_score: 4)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: sufficient_student_survey_item_2, create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: sufficient_student_survey_item_2,
academic_year:, school:, likert_score: 4) academic_year:, school:, likert_score: 4)
respondent
survey
end end
context 'when a students take a regular survey' do it 'returns a response rate equal to the response threshold' do
context 'when the average number of student responses per question in a subcategory is equal to the student response threshold' do expect(StudentResponseRateCalculator.new(subcategory:, school:,
academic_year:).rate).to eq 25
end
end
context 'when the average number of student responses per question is below the student threshold' do
before :each do before :each do
create_list(:survey_item_response, 1, survey_item: sufficient_student_survey_item_1,
academic_year:, school:, likert_score: 4)
create_list(:survey_item_response, 1, survey_item: sufficient_student_survey_item_2,
academic_year:, school:, likert_score: 4)
respondent respondent
survey survey
end end
it 'returns a response rate equal to the response threshold' do it 'reports insufficient student responses' do
expect(StudentResponseRateCalculator.new(subcategory:, school:, expect(StudentResponseRateCalculator.new(subcategory:, school:,
academic_year:).rate).to eq 25 academic_year:).rate).to eq 13
expect(StudentResponseRateCalculator.new(subcategory:, school:,
academic_year:).meets_student_threshold?).to eq false
end end
end end
end end
context 'when students take the short form survey' do context 'when students take the short form survey' do
before :each do before :each do
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item,
academic_year:, school:, likert_score: 1)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: sufficient_student_survey_item_1,
academic_year:, school:, likert_score: 4)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: sufficient_student_survey_item_2,
academic_year:, school:, likert_score: 4)
respondent respondent
short_form_survey short_form_survey
end end
@ -93,6 +114,12 @@ describe ResponseRateCalculator, type: :model do
context 'when there is an imbalance in the response rate of the student items' do context 'when there is an imbalance in the response rate of the student items' do
context 'and one of the student items has no associated survey item responses' do context 'and one of the student items has no associated survey item responses' do
before do before do
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item,
academic_year:, school:, likert_score: 1)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: sufficient_student_survey_item_1,
academic_year:, school:, likert_score: 4)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: sufficient_student_survey_item_2,
academic_year:, school:, likert_score: 4)
create(:respondent, school:, academic_year:) create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:) create(:survey, school:, academic_year:)
insufficient_student_survey_item_1 insufficient_student_survey_item_1

Loading…
Cancel
Save