From 4104eba990d927981d4394615eae28d46a6f14f1 Mon Sep 17 00:00:00 2001 From: Avin Hurry Date: Thu, 5 Sep 2024 20:55:40 +0100 Subject: [PATCH] [2267] Implement training route Add a way to calculate training routes based on funding and course type --- app/models/course.rb | 11 +++++++++++ spec/models/course_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/app/models/course.rb b/app/models/course.rb index bcf2d787e8..265bbe4946 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -10,6 +10,13 @@ class Course < ApplicationRecord A_LEVEL_ATTRIBUTES = %i[a_level_subject_requirements accept_pending_a_level accept_a_level_equivalency additional_a_level_equivalencies].freeze + TRAINING_ROUTE_MAP = { + %w[postgraduate fee] => 'fee_funded_initial_teacher_training', + %w[postgraduate salary] => 'school_direct_salaried', + %w[postgraduate apprenticeship] => 'postgraduate_teacher_apprenticeship', + %w[undergraduate salary] => 'teacher_degree_apprenticeship' + }.freeze + after_initialize :set_defaults before_discard do @@ -752,6 +759,10 @@ def funding_type=(funding_type) Courses::AssignProgramTypeService.new.execute(funding_type, self) end + def training_route + TRAINING_ROUTE_MAP.fetch([course_type, funding_type], 'unknown_training_route') + end + def ensure_site_statuses_match_study_mode site_statuses.not_no_vacancies.each do |site_status| update_vac_status(study_mode, site_status) diff --git a/spec/models/course_spec.rb b/spec/models/course_spec.rb index 65d07abdad..5417df8b7a 100644 --- a/spec/models/course_spec.rb +++ b/spec/models/course_spec.rb @@ -3450,4 +3450,31 @@ end end end + + describe '#training_route' do + it 'returns teacher_degree_apprenticeship for undergraduate and salaried' do + course = build(:course, funding: 'salary', course_type: 'undergraduate') + expect(course.training_route).to eq('teacher_degree_apprenticeship') + end + + it 'returns school_direct_salaried for postgraduate and salaried' do + course = build(:course, funding: 'salary', course_type: 'postgraduate') + expect(course.training_route).to eq('school_direct_salaried') + end + + it 'returns postgraduate_teaching_apprenticeship for postgraduate and apprenticeship' do + course = build(:course, funding: 'apprenticeship', course_type: 'postgraduate') + expect(course.training_route).to eq('postgraduate_teacher_apprenticeship') + end + + it 'returns fee_funded_initial_teacher_training for postgraduate and fee' do + course = build(:course, funding: 'fee', course_type: 'postgraduate') + expect(course.training_route).to eq('fee_funded_initial_teacher_training') + end + + it 'returns unknown_training_route for unknown course_type and funding_type combination' do + course = build(:course, funding: 'fee', course_type: 'undergraduate') + expect(course.training_route).to eq('unknown_training_route') + end + end end