Skip to content

Commit

Permalink
Ensure TDA defauls are handled when change the qualification
Browse files Browse the repository at this point in the history
When changing from non TDA to TDA course:
  Make sure full time is set on site statuses

When changing from TDA to non TDA course:
  Make sure A level is clear
  • Loading branch information
tomas-stefano committed Jul 10, 2024
1 parent ffd59fa commit a0862ee
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 20 deletions.
18 changes: 0 additions & 18 deletions app/controllers/concerns/study_mode_vacancy_mapper.rb

This file was deleted.

10 changes: 9 additions & 1 deletion app/controllers/publish/courses/outcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ def errors

def handle_qualification_update
if undergraduate_to_other_qualification?

@course.enrichments.find_or_initialize_draft.update(course_length: nil, salary_details: nil)
@course.update(
a_level_subject_requirements: [],
accept_pending_a_level: nil,
accept_a_level_equivalency: nil,
additional_a_level_equivalencies: nil
)

redirect_to funding_type_publish_provider_recruitment_cycle_course_path(
@course.provider_code,
Expand All @@ -64,7 +69,10 @@ def handle_qualification_update
else
if undergraduate_degree_with_qts?
Publish::Courses::AssignTdaAttributesService.new(@course).call

@course.save

@course.ensure_site_statuses_match_full_time
end

redirect_to details_publish_provider_recruitment_cycle_course_path(
Expand Down
20 changes: 19 additions & 1 deletion app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Course < ApplicationRecord
include ChangedAt
include TouchProvider
include Courses::EditOptions
include StudyModeVacancyMapper
include TimeFormat

after_initialize :set_defaults
Expand Down Expand Up @@ -811,8 +810,27 @@ def find_a_level_subject_requirement!(uuid)
requirement.with_indifferent_access
end

def ensure_site_statuses_match_full_time
site_statuses.each do |site_status|
update_vac_status('full_time', site_status)
end
end

private

def update_vac_status(study_mode, site_status)
case study_mode
when 'full_time'
site_status.update(vac_status: :full_time_vacancies)
when 'part_time'
site_status.update(vac_status: :part_time_vacancies)
when 'full_time_or_part_time'
site_status.update(vac_status: :both_full_time_and_part_time_vacancies)
else
raise "Unexpected study mode #{study_mode}"
end
end

def add_site!(site:)
is_course_new = ucas_status == :new
site_status = site_statuses.find_or_initialize_by(site:)
Expand Down
75 changes: 75 additions & 0 deletions spec/controllers/publish/courses/outcome_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Publish::Courses::OutcomeController do
let(:recruitment_cycle) { create(:recruitment_cycle, year: 2025) }
let(:user) { create(:user, providers: [build(:provider, recruitment_cycle:)]) }
let(:provider) { user.providers.first }

before do
allow(controller).to receive(:authenticate).and_return(true)
controller.instance_variable_set(:@current_user, user)
allow(Settings.features).to receive(:teacher_degree_apprenticeship).and_return(true)
end

describe '#update' do
context 'when changing from a QTS to teacher degree apprenticeship course' do
it 'assigns teacher degree apprenticeship course defaults' do
course = create(
:course,
:resulting_in_qts,
provider:,
study_mode: :part_time,
site_statuses: [build(:site_status, :part_time_vacancies, :findable)]
)
create(:course_enrichment, :initial_draft, course_length: :TwoYears, course:)

put :update, params: {
course: { qualification: 'undergraduate_degree_with_qts' },
provider_code: provider.provider_code,
recruitment_cycle_year: provider.recruitment_cycle_year,
code: course.course_code
}

course.reload

expect(course.funding_type).to eq('apprenticeship')
expect(course.can_sponsor_skilled_worker_visa).to be(false)
expect(course.can_sponsor_student_visa).to be(false)
expect(course.additional_degree_subject_requirements).to be(false)
expect(course.degree_subject_requirements).to be_nil
expect(course.degree_grade).to eq('not_required')
expect(course.study_mode).to eq('full_time')
expect(course.site_statuses.map(&:vac_status).uniq.first).to eq('full_time_vacancies')
expect(course.enrichments.max_by(&:created_at).course_length).to eq('4 years')
end
end

context 'when changing from teacher degree apprenticeship to a QTS course' do
it 'clear teacher degree specific defaults' do
course = create(
:course,
:with_teacher_degree_apprenticeship,
:resulting_in_undergraduate_degree_with_qts,
:with_a_level_requirements,
provider:
)

put :update, params: {
course: { qualification: 'qts' },
provider_code: provider.provider_code,
recruitment_cycle_year: provider.recruitment_cycle_year,
code: course.course_code
}

course.reload

expect(course.a_level_subject_requirements).to eq([])
expect(course.accept_a_level_equivalency).to be_nil
expect(course.accept_pending_a_level).to be_nil
expect(course.additional_a_level_equivalencies).to be_nil
end
end
end
end
16 changes: 16 additions & 0 deletions spec/models/course_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3018,6 +3018,22 @@
end
end

describe '#ensure_site_statuses_match_full_time' do
it 'updates all site statuses to full_time_vacancies' do
course = create(:course, study_mode: :part_time)
site_status_part_time = create(:site_status, course:, vac_status: :part_time_vacancies)

course.study_mode = 'full_time'
course.ensure_site_statuses_match_full_time

course.reload
site_status_part_time.reload

expect(site_status_part_time.vac_status).to eq('full_time_vacancies')
expect(course.site_statuses.map(&:vac_status).first).to eq('full_time_vacancies')
end
end

describe 'funding_type and program_type' do
context 'setting the funding_type to apprenticeship' do
it 'sets the funding_type to apprenticeship and program_type to pg_teaching_apprenticeship' do
Expand Down

0 comments on commit a0862ee

Please sign in to comment.