From 2e8f53464df98a1cfe97f2481159cddbfa204b4f Mon Sep 17 00:00:00 2001 From: Mooktakim Ahmed Date: Mon, 6 Jan 2025 15:12:38 +0000 Subject: [PATCH] [CPDLP-3898] Mentor Funding - Add new field to cohort to indicate Mentor funding --- app/services/importers/create_cohort.rb | 1 + config/analytics.yml | 1 + db/data/cohorts/cohorts.csv | 13 ++++---- ...106145039_add_mentor_funding_to_cohorts.rb | 7 +++++ db/schema.rb | 3 +- spec/factories/cohorts.rb | 1 + spec/services/importers/create_cohort_spec.rb | 30 ++++++++++++++----- 7 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20250106145039_add_mentor_funding_to_cohorts.rb diff --git a/app/services/importers/create_cohort.rb b/app/services/importers/create_cohort.rb index 63a537ca1f8..5a7c329e4ed 100644 --- a/app/services/importers/create_cohort.rb +++ b/app/services/importers/create_cohort.rb @@ -41,6 +41,7 @@ def create_cohort(row) npq_registration_start_date: safe_parse(row["npq-registration-start-date"]), automatic_assignment_period_end_date: safe_parse(row["automatic-assignment-period-end-date"]) || default_automatic_assignment_period_end_date, payments_frozen_at: safe_parse(row["payments-frozen-at"]).presence, + mentor_funding: (row["mentor-funding"] == "true"), created_at: Time.zone.now, updated_at: Time.zone.now, }, diff --git a/config/analytics.yml b/config/analytics.yml index f5bbf3b20eb..12cd47680b2 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -273,6 +273,7 @@ - npq_registration_start_date - automatic_assignment_period_end_date - payments_frozen_at + - mentor_funding :provider_relationships: - id - lead_provider_id diff --git a/db/data/cohorts/cohorts.csv b/db/data/cohorts/cohorts.csv index 5c45172b3e0..e7c77c860d3 100644 --- a/db/data/cohorts/cohorts.csv +++ b/db/data/cohorts/cohorts.csv @@ -1,6 +1,7 @@ -start-year,registration-start-date,academic-year-start-date,npq-registration-start-date,automatic-assignment-period-end-date,payments-frozen-at -2020,2020/05/10,2020/09/01,,2021/03/31, -2021,2021/05/10,2021/09/01,,2022/03/31,2024/04/03 -2022,2022/05/10,2022/09/01,,2023/03/31, -2023,2023/06/05,2023/09/01,2023/04/03,2024/03/31, -2024,2024/04/03,2024/09/01,2024/04/03,2025/03/31, +start-year,registration-start-date,academic-year-start-date,npq-registration-start-date,automatic-assignment-period-end-date,payments-frozen-at,mentor-funding +2020,2020/05/10,2020/09/01,,2021/03/31,,false +2021,2021/05/10,2021/09/01,,2022/03/31,2024/04/03,false +2022,2022/05/10,2022/09/01,,2023/03/31,,false +2023,2023/06/05,2023/09/01,2023/04/03,2024/03/31,,false +2024,2024/04/03,2024/09/01,2024/04/03,2025/03/31,,false +2025,2025/04/03,2025/09/01,2025/04/03,2026/03/31,,true diff --git a/db/migrate/20250106145039_add_mentor_funding_to_cohorts.rb b/db/migrate/20250106145039_add_mentor_funding_to_cohorts.rb new file mode 100644 index 00000000000..ef45c9d9d47 --- /dev/null +++ b/db/migrate/20250106145039_add_mentor_funding_to_cohorts.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddMentorFundingToCohorts < ActiveRecord::Migration[7.1] + def change + add_column :cohorts, :mentor_funding, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 523d992ab6a..8c1c1ba1e0e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_11_01_133851) do +ActiveRecord::Schema[7.1].define(version: 2025_01_06_145039) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "fuzzystrmatch" @@ -262,6 +262,7 @@ t.datetime "npq_registration_start_date", precision: nil t.date "automatic_assignment_period_end_date" t.datetime "payments_frozen_at" + t.boolean "mentor_funding", default: false, null: false t.index ["start_year"], name: "index_cohorts_on_start_year", unique: true end diff --git a/spec/factories/cohorts.rb b/spec/factories/cohorts.rb index 37322bd0d5d..e30c73437a5 100644 --- a/spec/factories/cohorts.rb +++ b/spec/factories/cohorts.rb @@ -10,6 +10,7 @@ registration_start_date { Date.new(start_year.to_i, 6, 5) } academic_year_start_date { Date.new(start_year.to_i, 9, 1) } automatic_assignment_period_end_date { Date.new(start_year.to_i + 1, 3, 31) } + mentor_funding { false } initialize_with do Cohort.find_by(start_year:) || new(**attributes) diff --git a/spec/services/importers/create_cohort_spec.rb b/spec/services/importers/create_cohort_spec.rb index a59ccd16bad..8305624d3f4 100644 --- a/spec/services/importers/create_cohort_spec.rb +++ b/spec/services/importers/create_cohort_spec.rb @@ -11,15 +11,15 @@ describe "#call" do context "with new cohorts" do before do - csv.write "start-year,registration-start-date,academic-year-start-date,npq-registration-start-date,automatic-assignment-period-end-date,payments-frozen-at" + csv.write "start-year,registration-start-date,academic-year-start-date,npq-registration-start-date,automatic-assignment-period-end-date,payments-frozen-at,mentor-funding" csv.write "\n" - csv.write "3030,3030/05/10,3030/09/01,3031/03/31,," + csv.write "3030,3030/05/10,3030/09/01,3031/03/31,,,true" csv.write "\n" - csv.write "3031,3031/05/10,3031/09/01,3032/03/31,," + csv.write "3031,3031/05/10,3031/09/01,3032/03/31,,,false" csv.write "\n" - csv.write "3032,3032/05/10,3032/09/01,,," + csv.write "3032,3032/05/10,3032/09/01,,,,true" csv.write "\n" - csv.write "3033,3033/05/10,3033/09/01,3034/03/31,," + csv.write "3033,3033/05/10,3033/09/01,3034/03/31,,,false" csv.write "\n" csv.close end @@ -61,6 +61,18 @@ expect(Cohort.select("start_year").group("start_year").pluck(:start_year).size).to be original_cohort_count + 4 end + + it "sets correctly mentor_funding field" do + importer.call + + Cohort.where(start_year: [3030, 3032]).each do |cohort| + expect(cohort.mentor_funding).to be(true) + end + + Cohort.where(start_year: [3031, 3033]).each do |cohort| + expect(cohort.mentor_funding).to be(false) + end + end end context "with existing cohorts" do @@ -68,13 +80,14 @@ FactoryBot.create :seed_cohort, start_year: 4041, registration_start_date: Date.new(4041, 5, 1), - academic_year_start_date: Date.new(4041, 8, 31) + academic_year_start_date: Date.new(4041, 8, 31), + mentor_funding: true end before do - csv.write "start-year,registration-start-date,academic-year-start-date,npq-registration-start-date,automatic-assignment-period-end-date,payments-frozen-at" + csv.write "start-year,registration-start-date,academic-year-start-date,npq-registration-start-date,automatic-assignment-period-end-date,payments-frozen-at,mentor-funding" csv.write "\n" - csv.write "4041,4041/05/10,4041/09/01,4041/04/01,4042/03/31," + csv.write "4041,4041/05/10,4041/09/01,4041/04/01,4042/03/31,,false" csv.write "\n" csv.close end @@ -88,6 +101,7 @@ registration_start_date: Date.new(4041, 5, 10), academic_year_start_date: Date.new(4041, 9, 1), npq_registration_start_date: Date.new(4041, 4, 1), + mentor_funding: false, ) end end