Skip to content

Commit

Permalink
Infer show placement subtype from the type
Browse files Browse the repository at this point in the history
  • Loading branch information
inulty-dfe committed Jan 18, 2024
1 parent 8be482a commit e381d24
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/components/find/courses/about_schools_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def render?
def show_higher_education_guidance?
return false unless course.higher_education_programme?

course_information_config.show_placement_guidance?(:program_type, :higher_education)
course_information_config.show_placement_guidance?(:program_type)
end

def show_scitt_guidance?
return false unless course.scitt_programme?

course_information_config.show_placement_guidance?(:program_type, :scitt_programmes)
course_information_config.show_placement_guidance?(:program_type)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,11 @@ def course_information
end

def show_scitt_guidance?
return false unless @course.scitt_programme?

course_information.show_placement_guidance?(:program_type, :scitt_programmes)
course_information.show_placement_guidance?(:program_type)
end

def show_universities_guidance?
return false unless @provider.university?

course_information.show_placement_guidance?(:provider_type, :universities)
course_information.show_placement_guidance?(:provider_type)
end
helper_method :show_scitt_guidance?, :show_universities_guidance?
end
Expand Down
11 changes: 9 additions & 2 deletions app/services/configs/course_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ def initialize(course)
@course = course
end

def show_placement_guidance?(type, subtype)
@db.dig(:placements, type, subtype, :except_provider_codes).exclude?(@course.provider.provider_code)
def show_placement_guidance?(type)
case type
when :provider_type
subtype = @course.provider.provider_type
when :program_type
subtype = @course.program_type
end

@db.dig(:placements, type, subtype.to_sym, :except_provider_codes)&.exclude?(@course.provider.provider_code)
end

def contact_form
Expand Down
6 changes: 3 additions & 3 deletions config/course_information.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
shared:
placements:
provider_type:
universities:
university:
except_provider_codes:
- B31
program_type:
scitt_programmes:
scitt_programme:
except_provider_codes:
- E65
higher_education:
higher_education_programme:
except_provider_codes:
- B31
show_address:
Expand Down
20 changes: 6 additions & 14 deletions spec/services/configs/course_information_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,85 +9,77 @@
let(:he_course) { build(:course, :with_higher_education, provider:, course_code:) }
let(:scitt_course) { build(:course, :with_scitt, provider:, course_code:) }

let(:type) { :provider_type }
let(:subtype) { :program_type }

let(:provider_code) { 'XXX' }
let(:course_code) { 'XXX' }

describe '#show_placement_guidance?' do
let(:course) { scitt_course }
let(:provider) { university_provider }
let(:type) { :provider_type }
let(:subtype) { :universities }

context 'when University providers provider code is present' do
let(:provider_code) { 'B31' }

it 'returns false' do
obj = described_class.new(course)

expect(obj.show_placement_guidance?(type, subtype)).to be(false)
expect(obj.show_placement_guidance?(type)).to be(false)
end
end

context 'when University providers provider_code is absent' do
it 'returns true' do
obj = described_class.new(course)

expect(obj.show_placement_guidance?(type, subtype)).to be(true)
expect(obj.show_placement_guidance?(type)).to be(true)
end
end

context 'when SCITT course with provider_code present' do
let(:provider) { scitt_provider }
let(:type) { :program_type }
let(:subtype) { :scitt_programmes }
let(:provider_code) { 'E65' }

it 'returns false' do
obj = described_class.new(course)

expect(obj.show_placement_guidance?(type, subtype)).to be(false)
expect(obj.show_placement_guidance?(type)).to be(false)
end
end

context 'when SCITT course with provider_code absent' do
let(:provider) { scitt_provider }
let(:type) { :program_type }
let(:subtype) { :scitt_programmes }

it 'returns true' do
obj = described_class.new(course)

expect(obj.show_placement_guidance?(type, subtype)).to be(true)
expect(obj.show_placement_guidance?(type)).to be(true)
end
end

context 'when Higher Education course with provider_code present' do
let(:course) { he_course }
let(:provider) { scitt_provider }
let(:type) { :program_type }
let(:subtype) { :higher_education }
let(:provider_code) { 'B31' }

it 'returns false' do
obj = described_class.new(course)

expect(obj.show_placement_guidance?(type, subtype)).to be(false)
expect(obj.show_placement_guidance?(type)).to be(false)
end
end

context 'when Higher Education course with provider_code absent' do
let(:course) { he_course }
let(:provider) { scitt_provider }
let(:type) { :program_type }
let(:subtype) { :higher_education }

it 'returns true' do
obj = described_class.new(course)

expect(obj.show_placement_guidance?(type, subtype)).to be(true)
expect(obj.show_placement_guidance?(type)).to be(true)
end
end
end
Expand Down

0 comments on commit e381d24

Please sign in to comment.