sqm-dashboards/spec/services/staffing_loader_spec.rb
Nelson Jovel 33da0859b9 Split academic year into seasons if the academic year's range is
initialized with a season, i.e. "2024-25 Fall".  Update scapers for
admin data, enrollment and staffing to use the new range standard
correctly.   Update the loaders for admin data, enrollment and staffing
so that it populates all seasons in a given year.  So admin data for
2024-25 gets loaded into "2024-25 Fall" and "2024-25 Spring".  Add tests
for the new range format.  Set the default cutoff for the start of Spring season will be the last Sunday in February
2024-04-25 09:21:04 -07:00

77 lines
2.9 KiB
Ruby

require "rails_helper"
describe StaffingLoader do
let(:path_to_staffing_data) { Rails.root.join("spec", "fixtures", "sample_staffing_data.csv") }
let(:ay_2020_21) { create(:academic_year, range: "2020-21") }
let(:ay_2021_22) { create(:academic_year, range: "2021-22") }
let(:ay_2022_23) { create(:academic_year, range: "2022-23") }
let(:ay_2023_24_fall) { create(:academic_year, range: "2023-24 Fall") }
let(:ay_2023_24_spring) { create(:academic_year, range: "2023-24 Spring") }
let(:attleboro) { create(:school, name: "Attleboro", dese_id: 160_505) }
let(:beachmont) { create(:school, name: "Beachmont", dese_id: 2_480_013) }
let(:winchester) { create(:school, name: "Winchester", dese_id: 3_440_505) }
before :each do
ay_2020_21
ay_2021_22
ay_2022_23
ay_2023_24_fall
ay_2023_24_spring
attleboro
beachmont
winchester
end
context "self.load_data" do
before do
StaffingLoader.load_data filepath: path_to_staffing_data
end
it "loads the correct staffing numbers" do
academic_year = ay_2021_22
expect(Respondent.find_by(school: attleboro, academic_year:).total_teachers).to eq 197.5
expect(Respondent.find_by(school: beachmont, academic_year:).total_teachers).to eq 56.4
expect(Respondent.find_by(school: winchester, academic_year:).total_teachers).to eq 149.8
end
end
context "self.clone_previous_year_data" do
before do
StaffingLoader.load_data filepath: path_to_staffing_data
StaffingLoader.clone_previous_year_data
end
it "fills in empty staffing numbers with the previous years data" do
academic_year = ay_2022_23
expect(Respondent.find_by(school: attleboro, academic_year:).total_teachers).to eq 197.5
expect(Respondent.find_by(school: beachmont, academic_year:).total_teachers).to eq 56.4
expect(Respondent.find_by(school: winchester, academic_year:).total_teachers).to eq 149.8
academic_year = ay_2023_24_fall
expect(Respondent.find_by(school: attleboro, academic_year:).total_teachers).to eq 197.5
expect(Respondent.find_by(school: beachmont, academic_year:).total_teachers).to eq 56.4
expect(Respondent.find_by(school: winchester, academic_year:).total_teachers).to eq 149.8
academic_year = ay_2023_24_spring
expect(Respondent.find_by(school: attleboro, academic_year:).total_teachers).to eq 197.5
expect(Respondent.find_by(school: beachmont, academic_year:).total_teachers).to eq 56.4
expect(Respondent.find_by(school: winchester, academic_year:).total_teachers).to eq 149.8
# Does not touch existing numbers
academic_year = ay_2020_21
expect(Respondent.find_by(school: attleboro, academic_year:).total_teachers).to eq 100
expect(Respondent.find_by(school: beachmont, academic_year:).total_teachers).to eq 100
expect(Respondent.find_by(school: winchester, academic_year:).total_teachers).to eq 100
end
end
end