Skip to content

Commit

Permalink
Merge pull request #4034 from DFE-Digital/1240-investigate-and-fix-va…
Browse files Browse the repository at this point in the history
…lidation-failing-on-applicationopenfrom

[1240] validate `applications_open_from` when publishing a course
  • Loading branch information
avinhurry authored Feb 1, 2024
2 parents ec785d1 + 669be68 commit 75ab999
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/helpers/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def enrichment_error_url(provider_code:, course:, field:, message: nil)
age_range_in_years: "#{base}/age-range?display_errors=true",
sites: "#{base}/schools?display_errors=true",
study_sites: (course.provider&.study_sites&.none? ? "#{provider_base}/study-sites" : "#{base}/study-sites").to_s,
accrediting_provider: accredited_provider_publish_provider_recruitment_cycle_course_path(course.provider_code, course.recruitment_cycle_year, course.course_code)
accrediting_provider: accredited_provider_publish_provider_recruitment_cycle_course_path(course.provider_code, course.recruitment_cycle_year, course.course_code),
applications_open_from: "#{base}/applications-open"
}.with_indifferent_access[field]
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def self.entry_requirement_options_without_nil_choice
validate :validate_enrichment
validate :validate_qualification, on: %i[update new]
validate :validate_start_date, on: :update, if: -> { provider.present? && start_date.present? }
validate :validate_applications_open_from, on: %i[update new], if: -> { provider.present? }
validate :validate_applications_open_from, on: %i[publish update new], if: -> { provider.present? }
validate :validate_modern_languages
validate :validate_has_languages, if: :has_the_modern_languages_secondary_subject_type?
validate :validate_subject_count
Expand Down
4 changes: 4 additions & 0 deletions spec/helpers/view_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
it 'returns enrichment error URL for base error' do
expect(enrichment_error_url(provider_code: 'A1', course:, field: 'base', message: 'Select if student visas can be sponsored')).to eq("/publish/organisations/A1/#{Settings.current_recruitment_cycle_year}/student-visa")
end

it 'returns the course applications open date url for the error' do
expect(enrichment_error_url(provider_code: provider.provider_code, course:, field: 'applications_open_from')).to eq("/publish/organisations/#{provider.provider_code}/#{Settings.current_recruitment_cycle_year}/courses/#{course.course_code}/applications-open")
end
end

describe '#provider_enrichment_error_url' do
Expand Down
11 changes: 10 additions & 1 deletion spec/models/course_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,22 @@
let(:course) { create(:course, :without_validation, age_range_in_years: nil) }
let(:errors) { course.errors.messages }

before { course.valid?(:publish) }
before do
course.applications_open_from = course.recruitment_cycle.application_start_date - 1
course.valid?(:publish)
end

it 'requires age_range_in_years' do
error = errors[:age_range_in_years]
expect(error).not_to be_empty
expect(error.first).to include('Select an age range')
end

it 'requires a applications_open_from date inside of the current recruitment cycle' do
error = course.errors.messages[:applications_open_from]
expect(error).not_to be_empty
expect(error.first).to include("is not valid for the #{Settings.current_recruitment_cycle_year} cycle. A valid date must be between")
end
end

context 'A further education course' do
Expand Down

0 comments on commit 75ab999

Please sign in to comment.