mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-08 23:18:18 -07:00
fix: correctly load survey items from sample framework file. Fix broken tests
This commit is contained in:
parent
07836cc020
commit
f689ee8ee5
7 changed files with 414 additions and 305 deletions
|
|
@ -1,8 +1,8 @@
|
|||
require 'rails_helper'
|
||||
require "rails_helper"
|
||||
RSpec.describe Report::Subcategory, type: :model do
|
||||
let(:school) { create(:school, name: 'Milford High', slug: 'milford-high') }
|
||||
let(:academic_year) { create(:academic_year, range: '2018-2019') }
|
||||
let(:subcategory) { create(:subcategory, subcategory_id: '1A') }
|
||||
let(:school) { create(:school, name: "Milford High", slug: "milford-high") }
|
||||
let(:academic_year) { create(:academic_year, range: "2018-2019") }
|
||||
let(:subcategory) { create(:subcategory, subcategory_id: "1A") }
|
||||
let(:respondent) { create(:respondent, school:, academic_year:) }
|
||||
before :each do
|
||||
school
|
||||
|
|
@ -14,64 +14,68 @@ RSpec.describe Report::Subcategory, type: :model do
|
|||
let(:scale) { create(:scale, measure:) }
|
||||
let(:survey_item) { create(:student_survey_item, scale:) }
|
||||
|
||||
context 'when creating a report for a subcategory' do
|
||||
context "when creating a report for a subcategory" do
|
||||
before :each do
|
||||
create_list(:survey_item_response, 10, survey_item:, school:, academic_year:)
|
||||
end
|
||||
|
||||
it 'creates a report for subcategories' do
|
||||
expect(Report::Subcategory.create_report).to be_a(Array)
|
||||
headers = Report::Subcategory.create_report.first
|
||||
expect(headers).to eq(['District', 'School', 'School Code', 'Academic Year', 'Recorded Date Range', 'Grades', 'Subcategory', 'Student Score',
|
||||
'Student Zone', 'Teacher Score', 'Teacher Zone', 'Admin Score', 'Admin Zone', 'All Score (Average)', 'All Score Zone'])
|
||||
it "creates a report for subcategories with the correct headers" do
|
||||
report = Report::Subcategory.create_report
|
||||
csv = CSV.parse(report, headers: true)
|
||||
headers = csv.headers
|
||||
expect(headers).to be_a(Array)
|
||||
expect(headers).to eq(["District", "School", "School Code", "Academic Year", "Recorded Date Range", "Grades", "Subcategory", "Student Score",
|
||||
"Student Zone", "Teacher Score", "Teacher Zone", "Admin Score", "Admin Zone", "All Score (Average)", "All Score Zone"])
|
||||
end
|
||||
|
||||
it 'Adds information about the first school and first academic year to the report' do
|
||||
it "Adds information about the first school and first academic year to the report" do
|
||||
report = Report::Subcategory.create_report
|
||||
report[1] in [district, school_name, school_code, academic_year, recorded_date_range, grades, subcategory_id, *]
|
||||
expect(school_name).to eq('Milford High')
|
||||
expect(academic_year).to eq('2018-2019')
|
||||
expect(subcategory_id).to eq('1A')
|
||||
csv = CSV.parse(report, headers: true)
|
||||
csv.first in [district, school_name, school_code, academic_year, recorded_date_range, grades, subcategory_id, *]
|
||||
expect(school_name).to eq("Milford High")
|
||||
expect(academic_year).to eq("2018-2019")
|
||||
expect(subcategory_id).to eq("1A")
|
||||
end
|
||||
end
|
||||
describe '.create_report' do
|
||||
describe ".create_report" do
|
||||
before do
|
||||
allow(Report::Subcategory).to receive(:write_csv)
|
||||
end
|
||||
|
||||
it 'generates a CSV report' do
|
||||
expect(FileUtils).to receive(:mkdir_p).with(Rails.root.join('tmp', 'reports'))
|
||||
it "generates a CSV report" do
|
||||
expect(FileUtils).to receive(:mkdir_p).with(Rails.root.join("tmp", "reports"))
|
||||
|
||||
Report::Subcategory.create_report
|
||||
|
||||
expect(Report::Subcategory).to have_received(:write_csv)
|
||||
end
|
||||
|
||||
it 'returns the report data' do
|
||||
data = Report::Subcategory.create_report
|
||||
|
||||
expect(data).to be_an(Array)
|
||||
end
|
||||
end
|
||||
describe '.write_csv' do
|
||||
it 'writes the data to a CSV file' do
|
||||
data = [['School', 'Academic Year', 'Subcategory'], ['School A', '2022-2023', 'Category A']]
|
||||
filepath = Rails.root.join('tmp', 'spec', 'reports', 'subcategories.csv')
|
||||
describe ".write_csv" do
|
||||
it "writes the data to a CSV file" do
|
||||
data = [["School", "Academic Year", "Subcategory"], ["School A", "2022-2023", "Category A"]]
|
||||
|
||||
FileUtils.mkdir_p Rails.root.join('tmp', 'spec', 'reports')
|
||||
Report::Subcategory.write_csv(data:, filepath:)
|
||||
csv = CSV.generate do |csv|
|
||||
data.each do |row|
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
|
||||
filepath = Rails.root.join("tmp", "spec", "reports", "subcategories.csv")
|
||||
|
||||
FileUtils.mkdir_p Rails.root.join("tmp", "spec", "reports")
|
||||
Report::Subcategory.write_csv(csv:, filepath:)
|
||||
|
||||
csv_data = File.read(filepath)
|
||||
expect(csv_data).to include('School,Academic Year,Subcategory')
|
||||
expect(csv_data).to include('School A,2022-2023,Category A')
|
||||
expect(csv_data).to include("School,Academic Year,Subcategory")
|
||||
expect(csv_data).to include("School A,2022-2023,Category A")
|
||||
end
|
||||
end
|
||||
|
||||
describe '.student_score' do
|
||||
describe ".student_score" do
|
||||
let(:response_rate) { create(:response_rate, subcategory:, school:, academic_year:) }
|
||||
let(:row) { [response_rate, subcategory, school, academic_year] }
|
||||
|
||||
it 'returns student score if response rate meets student threshold' do
|
||||
it "returns student score if response rate meets student threshold" do
|
||||
allow(subcategory).to receive(:student_score).and_return(80)
|
||||
allow(response_rate).to receive(:meets_student_threshold?).and_return(true)
|
||||
|
||||
|
|
@ -85,7 +89,7 @@ RSpec.describe Report::Subcategory, type: :model do
|
|||
|
||||
score = Report::Subcategory.student_score(row:)
|
||||
|
||||
expect(score).to eq('N/A')
|
||||
expect(score).to eq("N/A")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue