Skip to content

Commit

Permalink
[CPDLP-3898] Mentor Funding - Add new field to cohort to indicate Men…
Browse files Browse the repository at this point in the history
…tor funding
  • Loading branch information
mooktakim committed Jan 6, 2025
1 parent 5212e77 commit 2e8f534
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/services/importers/create_cohort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
- npq_registration_start_date
- automatic_assignment_period_end_date
- payments_frozen_at
- mentor_funding
:provider_relationships:
- id
- lead_provider_id
Expand Down
13 changes: 7 additions & 6 deletions db/data/cohorts/cohorts.csv
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions db/migrate/20250106145039_add_mentor_funding_to_cohorts.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions spec/factories/cohorts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 22 additions & 8 deletions spec/services/importers/create_cohort_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,20 +61,33 @@

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
let!(:cohort) do
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
Expand All @@ -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
Expand Down

0 comments on commit 2e8f534

Please sign in to comment.