From 555e32884b94b1cc996a19e11ebe99e5e566debb Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Mon, 15 Jan 2024 15:41:04 +0000 Subject: [PATCH 01/10] Move Provider Codes from view templates to config Some view features are shown depending on the provider code of the courses provider or the type of course it is. We are moving this configuration into a config file now and passing a predicate to the view to control the visiblility of the content. --- .../courses/about_schools_component/view.rb | 3 +-- .../courses/course_information_controller.rb | 19 +++++++++++++++++++ .../courses/course_information/edit.html.erb | 4 ++-- config/course_information.yml | 8 ++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 config/course_information.yml diff --git a/app/components/find/courses/about_schools_component/view.rb b/app/components/find/courses/about_schools_component/view.rb index 8f45d34e21..74477bf98b 100644 --- a/app/components/find/courses/about_schools_component/view.rb +++ b/app/components/find/courses/about_schools_component/view.rb @@ -21,8 +21,7 @@ def initialize(course) def render? published_how_school_placements_work.present? || - program_type == 'higher_education_programme' || - program_type == 'scitt_programme' || + program_type.in?(%w[higher_education_programme scitt_programme]) || study_sites.any? || site_statuses.map(&:site).uniq.many? || preview?(params) end diff --git a/app/controllers/publish/courses/course_information_controller.rb b/app/controllers/publish/courses/course_information_controller.rb index 41ab3f2ddf..339a496d09 100644 --- a/app/controllers/publish/courses/course_information_controller.rb +++ b/app/controllers/publish/courses/course_information_controller.rb @@ -59,6 +59,25 @@ def course_enrichment end def param_form_key = :publish_course_information_form + + def course_information + @course_information ||= Rails.application.config_for('course_information').fetch(:where_you_will_train) + end + + def show_scitt_guidance? + return false unless @course.scitt_programme? + + codes = course_information.dig(:scitt_programmes, :except_provider_codes) + codes.exclude?(@course.provider.provider_code) + end + + def show_universities_guidance? + return false unless @provider.university? + + codes = course_information.dig(:universities, :except_provider_codes) + codes.exclude?(@course.provider.provider_code) + end + helper_method :show_scitt_guidance?, :show_universities_guidance? end end end diff --git a/app/views/publish/courses/course_information/edit.html.erb b/app/views/publish/courses/course_information/edit.html.erb index 1d26b383da..6462b195f0 100644 --- a/app/views/publish/courses/course_information/edit.html.erb +++ b/app/views/publish/courses/course_information/edit.html.erb @@ -98,14 +98,14 @@
  • how placement schools are selected
  • - <% if @provider.provider_type == 'university' && @provider.provider_code != 'B31' %> + <% if show_universities_guidance? %> <%= govuk_details(summary_text: "See the guidance we show in this section") do %>

    Where you will train

    You’ll be placed in schools for most of your course. Your school placements will be within commuting distance.

    You cannot pick which schools you want to be in, but your university will try to take your journey time into consideration.

    Universities can work with over 100 potential placement schools. Most will be within 10 miles of the university, but sometimes they can cover a wider area, especially outside of cities.

    <% end %> - <% elsif @course.program_type == 'scitt_programme' && @provider.provider_code != 'E65' %> + <% elsif show_scitt_guidance? %> <%= govuk_details(summary_text: "See the guidance we show in this section") do %>

    Where you will train

    You’ll be placed in different schools during your training. You can’t pick which schools you want to be in, but your training provider will place you in schools you can travel to.

    diff --git a/config/course_information.yml b/config/course_information.yml new file mode 100644 index 0000000000..54dbf94321 --- /dev/null +++ b/config/course_information.yml @@ -0,0 +1,8 @@ +shared: + where_you_will_train: + universities: + except_provider_codes: + - B31 + scitt_programmes: + except_provider_codes: + - E65 From 506fd8b94c59914ebf5d984c07a9538e73b2e0e1 Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Tue, 16 Jan 2024 13:03:00 +0000 Subject: [PATCH 02/10] Add spec for guidance on editing a course --- ...diting_course_information_guidance_spec.rb | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 spec/features/publish/courses/editing_course_information_guidance_spec.rb diff --git a/spec/features/publish/courses/editing_course_information_guidance_spec.rb b/spec/features/publish/courses/editing_course_information_guidance_spec.rb new file mode 100644 index 0000000000..b47098844d --- /dev/null +++ b/spec/features/publish/courses/editing_course_information_guidance_spec.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +require 'rails_helper' + +feature 'Guidance components on course edit page', { can_edit_current_and_next_cycles: false } do + describe 'university providers' do + context 'when provider is excluded via config' do + scenario 'Guidance is not shown' do + given_a_provider_which_does_not_show_guidance + and_the_provider_has_a_course + and_i_am_authenticated_as_a_provider_user + when_i_go_to_edit_a_course + i_do_not_see_the_guidance_text + end + + def given_a_provider_which_does_not_show_guidance + @provider = create(:provider, :university, provider_code: 'B31') + end + end + + context 'when provider is not excluded via config' do + scenario 'Guidance is shown' do + given_a_provider_which_does_show_guidance + and_the_provider_has_a_course + and_i_am_authenticated_as_a_provider_user + when_i_go_to_edit_a_course + i_do_see_the_guidance_text + end + + def given_a_provider_which_does_show_guidance + @provider = create(:provider, :university, provider_code: 'XXX') + end + end + end + + describe 'scitt courses' do + context 'when provider is excluded via config' do + scenario 'Guidance is not shown' do + given_a_provider_which_does_not_show_guidance + and_the_provider_has_a_course + and_i_am_authenticated_as_a_provider_user + when_i_go_to_edit_a_course + i_do_not_see_the_guidance_text + end + + def given_a_provider_which_does_not_show_guidance + @provider = create(:provider, :scitt, provider_code: 'E65') + end + end + + context 'when provider is not excluded via config' do + scenario 'Guidance is shown' do + given_a_provider_which_does_show_guidance + and_the_provider_has_a_course + and_i_am_authenticated_as_a_provider_user + when_i_go_to_edit_a_course + i_do_see_the_guidance_text + end + + def and_the_provider_has_a_course + @course = create(:course, :with_scitt, provider: @provider) + end + + def given_a_provider_which_does_show_guidance + @provider = create(:provider, :scitt, provider_code: 'T92') + end + end + end + + def and_the_provider_has_a_course + @course = create(:course, provider: @provider) + end + + def and_i_am_authenticated_as_a_provider_user + given_i_am_authenticated + @current_user.providers << @provider + end + + def when_i_go_to_edit_a_course + publish_course_information_edit_page.load( + provider_code: @provider.provider_code, recruitment_cycle_year: @provider.recruitment_cycle_year, course_code: @course.course_code + ) + end + + def i_do_not_see_the_guidance_text + expect(page).to have_no_content('Where you will train') + end + + def i_do_see_the_guidance_text + expect(page).to have_content('Where you will train') + end +end From 68ff9bc8f176a85e61fae95c898ca547d3c004e1 Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Mon, 15 Jan 2024 16:31:06 +0000 Subject: [PATCH 03/10] Find interface Course information guidance uses config Conditionally show course guidance based on provider code in config --- .../about_schools_component/view.html.erb | 4 ++-- .../courses/about_schools_component/view.rb | 20 +++++++++++++++++++ config/course_information.yml | 3 +++ .../about_schools_component/view_preview.rb | 4 ++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/components/find/courses/about_schools_component/view.html.erb b/app/components/find/courses/about_schools_component/view.html.erb index 438feac8d3..1809100f21 100644 --- a/app/components/find/courses/about_schools_component/view.html.erb +++ b/app/components/find/courses/about_schools_component/view.html.erb @@ -1,7 +1,7 @@

    Training locations

    - <% if course.program_type == "higher_education_programme" && course.provider.provider_code != "B31" %> + <% if show_higher_education_guidance? %> <%= render Find::Utility::AdviceComponent::View.new(title: "Where you will train") do %>

    You’ll be placed in schools for most of your course. Your school placements will be within commuting distance.

    @@ -10,7 +10,7 @@

    Universities can work with over 100 potential placement schools. Most will be within 10 miles of the university, but sometimes they can cover a wider area, especially outside of cities.

    <% end %> - <% elsif course.program_type == "scitt_programme" && course.provider.provider_code != "E65" %> + <% elsif show_scitt_guidance? %> <%= render Find::Utility::AdviceComponent::View.new(title: "Where you will train") do %>

    You’ll be placed in different schools during your training. You can’t pick which schools you want to be in, but your training provider will place you in schools you can travel to.

    <% end %> diff --git a/app/components/find/courses/about_schools_component/view.rb b/app/components/find/courses/about_schools_component/view.rb index 74477bf98b..1dbc25da19 100644 --- a/app/components/find/courses/about_schools_component/view.rb +++ b/app/components/find/courses/about_schools_component/view.rb @@ -25,6 +25,26 @@ def render? study_sites.any? || site_statuses.map(&:site).uniq.many? || preview?(params) end + + def show_higher_education_guidance? + return false unless course.higher_education_programme? + + course_information_config(:higher_education, :except_provider_codes).exclude?(course.provider.provider_code) + end + + def show_scitt_guidance? + return false unless course.scitt_programme? + + course_information_config(:scitt_programmes, :except_provider_codes).exclude?(course.provider_code) + end + + private + + def course_information_config(*path) + @course_information_config ||= Rails.application.config_for(:course_information) + + @course_information_config.dig(:where_you_will_train, *path) + end end end end diff --git a/config/course_information.yml b/config/course_information.yml index 54dbf94321..5dffbc6b94 100644 --- a/config/course_information.yml +++ b/config/course_information.yml @@ -6,3 +6,6 @@ shared: scitt_programmes: except_provider_codes: - E65 + higher_education: + except_provider_codes: + - B31 diff --git a/spec/components/find/courses/about_schools_component/view_preview.rb b/spec/components/find/courses/about_schools_component/view_preview.rb index f24b0688ac..5c5c64be0c 100644 --- a/spec/components/find/courses/about_schools_component/view_preview.rb +++ b/spec/components/find/courses/about_schools_component/view_preview.rb @@ -56,6 +56,10 @@ class FakeCourse include ActiveModel::Model attr_accessor(:provider, :published_how_school_placements_work, :placements_heading, :program_type, :study_sites, :site_statuses) + def higher_education_programme? + true + end + def preview_site_statuses site_statuses.sort_by { |status| status.site.location_name } end From a9bdedff7709d4429dea5d91deda303e1d2a156a Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Mon, 15 Jan 2024 17:39:24 +0000 Subject: [PATCH 04/10] Move logic for showing course provider address to config The course address is different for Provider 28T only for course X104. The logic for showing this is stored in the course_information config. --- .../find/courses/contact_details_component/view.html.erb | 2 +- .../find/courses/contact_details_component/view.rb | 8 ++++++++ config/course_information.yml | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/components/find/courses/contact_details_component/view.html.erb b/app/components/find/courses/contact_details_component/view.html.erb index d14489b8eb..1a472f3b4b 100644 --- a/app/components/find/courses/contact_details_component/view.html.erb +++ b/app/components/find/courses/contact_details_component/view.html.erb @@ -33,7 +33,7 @@ <% end %> - <% if course.provider.provider_code == "28T" && course.course_code == "X104" %> + <% if show_address? %>
    Address
    LSJS diff --git a/app/components/find/courses/contact_details_component/view.rb b/app/components/find/courses/contact_details_component/view.rb index c1da41ac22..9d618dbbb5 100644 --- a/app/components/find/courses/contact_details_component/view.rb +++ b/app/components/find/courses/contact_details_component/view.rb @@ -12,6 +12,14 @@ def initialize(course) super @course = course end + + def show_address? + course.provider_code.in?(course_information_config(:only_provider_codes)) && course.course_code.in?(course_information_config(:only_course_codes)) + end + + def course_information_config(*path) + Rails.application.config_for(:course_information).dig(:show_address, *path) + end end end end diff --git a/config/course_information.yml b/config/course_information.yml index 5dffbc6b94..0465a5bdee 100644 --- a/config/course_information.yml +++ b/config/course_information.yml @@ -9,3 +9,8 @@ shared: higher_education: except_provider_codes: - B31 + show_address: + only_provider_codes: + - 28T + only_course_codes: + - X104 From 9703ce359137267289db9d27fdf23fcfe5ad3298 Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Tue, 16 Jan 2024 10:40:55 +0000 Subject: [PATCH 05/10] Refactor Contact form display logic on course information Some providers may prefer to be contacted via web form rather than an email address. The present refactor shows the Contact form on the course information page if the provider is configured as such. We can add more providers to this configuration now as it's stored in a yaml database. --- .../contact_details_component/view.html.erb | 6 ++---- .../courses/contact_details_component/view.rb | 20 +++++++++++++++++-- config/course_information.yml | 2 ++ .../contact_details_component/view_spec.rb | 12 +++++++++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/components/find/courses/contact_details_component/view.html.erb b/app/components/find/courses/contact_details_component/view.html.erb index 1a472f3b4b..1bd0ecd30a 100644 --- a/app/components/find/courses/contact_details_component/view.html.erb +++ b/app/components/find/courses/contact_details_component/view.html.erb @@ -3,12 +3,10 @@
    - - <% if course.provider.provider_code == "U80" %> - <% link = "https://www.ucl.ac.uk/prospective-students/graduate/admissions-enquiries" %> + <% if show_contact_form_instead_of_email? %>
    Contact form
    - <%= govuk_link_to link, link %> + <%= govuk_link_to contact_form, contact_form %>
    <% else %> <% if course.provider.email.present? %> diff --git a/app/components/find/courses/contact_details_component/view.rb b/app/components/find/courses/contact_details_component/view.rb index 9d618dbbb5..46cbade326 100644 --- a/app/components/find/courses/contact_details_component/view.rb +++ b/app/components/find/courses/contact_details_component/view.rb @@ -13,12 +13,28 @@ def initialize(course) @course = course end + def show_contact_form_instead_of_email? + course.provider.provider_code.in?(course_information_config(:contact_forms).keys.map(&:to_s)) + end + def show_address? - course.provider_code.in?(course_information_config(:only_provider_codes)) && course.course_code.in?(course_information_config(:only_course_codes)) + course.provider_code.in?(course_information_config(:show_address, :only_provider_codes)) && course.course_code.in?(course_information_config(:show_address, :only_course_codes)) + end + + def contact_form + contact_forms[course.provider.provider_code] + end + + private + + def contact_forms + course_information_config(:contact_forms).stringify_keys end def course_information_config(*path) - Rails.application.config_for(:course_information).dig(:show_address, *path) + @course_information_config ||= Rails.application.config_for(:course_information) + + @course_information_config.dig(*path) end end end diff --git a/config/course_information.yml b/config/course_information.yml index 0465a5bdee..2bf0ac8b42 100644 --- a/config/course_information.yml +++ b/config/course_information.yml @@ -14,3 +14,5 @@ shared: - 28T only_course_codes: - X104 + contact_forms: + U80: https://www.ucl.ac.uk/prospective-students/graduate/admissions-enquiries diff --git a/spec/components/find/courses/contact_details_component/view_spec.rb b/spec/components/find/courses/contact_details_component/view_spec.rb index 684fa22d53..5eb5d6bf25 100644 --- a/spec/components/find/courses/contact_details_component/view_spec.rb +++ b/spec/components/find/courses/contact_details_component/view_spec.rb @@ -76,4 +76,16 @@ expect(result.text).to include('LSJS', '44A Albert Road', 'London', 'NW4 2SJ') end end + + context 'when the provider has a contact form in the config' do + it 'renders the Contact Form instead of Email' do + provider = build(:provider, provider_code: 'U80') + course = build(:course, course_code: 'X104', provider:).decorate + + result = render_inline(described_class.new(course)) + + expect(result.text).to include('Contact form') + expect(result.text).not_to include('Email') + end + end end From d583dc3ddb0fe331b67569c6bf8bed45fb4d0f2b Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Wed, 17 Jan 2024 09:39:15 +0000 Subject: [PATCH 06/10] Add Configs::CourseInformation Use a utility class to access the unique configurations that apply to certains courses and providers which are stored in a YAML config file. --- .../courses/contact_details_component/view.rb | 21 +++------------ app/services/configs/course_information.rb | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 app/services/configs/course_information.rb diff --git a/app/components/find/courses/contact_details_component/view.rb b/app/components/find/courses/contact_details_component/view.rb index 46cbade326..eeb74f3872 100644 --- a/app/components/find/courses/contact_details_component/view.rb +++ b/app/components/find/courses/contact_details_component/view.rb @@ -7,6 +7,7 @@ class View < ViewComponent::Base attr_reader :course delegate :provider, to: :course + delegate :contact_form?, :contact_form, :show_address?, to: :course_information_config def initialize(course) super @@ -14,27 +15,13 @@ def initialize(course) end def show_contact_form_instead_of_email? - course.provider.provider_code.in?(course_information_config(:contact_forms).keys.map(&:to_s)) - end - - def show_address? - course.provider_code.in?(course_information_config(:show_address, :only_provider_codes)) && course.course_code.in?(course_information_config(:show_address, :only_course_codes)) - end - - def contact_form - contact_forms[course.provider.provider_code] + contact_form? end private - def contact_forms - course_information_config(:contact_forms).stringify_keys - end - - def course_information_config(*path) - @course_information_config ||= Rails.application.config_for(:course_information) - - @course_information_config.dig(*path) + def course_information_config + @course_information_config ||= Configs::CourseInformation.new(course) end end end diff --git a/app/services/configs/course_information.rb b/app/services/configs/course_information.rb new file mode 100644 index 0000000000..e246a20579 --- /dev/null +++ b/app/services/configs/course_information.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Configs + class CourseInformation + def initialize(course) + @db = Rails.application.config_for(:course_information) + @course = course + end + + def placement(*path) + @db.dig(*path) + end + + def contact_form + @db.fetch(:contact_forms).stringify_keys[@course.provider.provider_code] + end + + def contact_form? + @db.fetch(:contact_forms).stringify_keys.include?(@course.provider.provider_code) + end + + def show_address? + @db.dig(:show_address, :only_provider_codes).include?(@course.provider.provider_code) && + @db.dig(:show_address, :only_course_codes).include?(@course.course_code) + end + end +end From c544aec585643739f2b121527cf96121b96e24ec Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Wed, 17 Jan 2024 10:29:20 +0000 Subject: [PATCH 07/10] Update about schools component to use Config::CourseInformation --- .../courses/about_schools_component/view.rb | 10 ++++----- app/services/configs/course_information.rb | 4 ++-- config/course_information.yml | 22 ++++++++++--------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/components/find/courses/about_schools_component/view.rb b/app/components/find/courses/about_schools_component/view.rb index 1dbc25da19..77faa82613 100644 --- a/app/components/find/courses/about_schools_component/view.rb +++ b/app/components/find/courses/about_schools_component/view.rb @@ -29,21 +29,19 @@ def render? def show_higher_education_guidance? return false unless course.higher_education_programme? - course_information_config(:higher_education, :except_provider_codes).exclude?(course.provider.provider_code) + course_information_config.placement(:program_type, :higher_education) end def show_scitt_guidance? return false unless course.scitt_programme? - course_information_config(:scitt_programmes, :except_provider_codes).exclude?(course.provider_code) + course_information_config.placement(:program_type, :scitt_programmes) end private - def course_information_config(*path) - @course_information_config ||= Rails.application.config_for(:course_information) - - @course_information_config.dig(:where_you_will_train, *path) + def course_information_config + @course_information_config ||= Configs::CourseInformation.new(course) end end end diff --git a/app/services/configs/course_information.rb b/app/services/configs/course_information.rb index e246a20579..fe3487d934 100644 --- a/app/services/configs/course_information.rb +++ b/app/services/configs/course_information.rb @@ -7,8 +7,8 @@ def initialize(course) @course = course end - def placement(*path) - @db.dig(*path) + def placement(type, subtype) + @db.dig(:placements, type, subtype, :except_provider_codes).exclude?(@course.provider.provider_code) end def contact_form diff --git a/config/course_information.yml b/config/course_information.yml index 2bf0ac8b42..c7a4cfcc39 100644 --- a/config/course_information.yml +++ b/config/course_information.yml @@ -1,14 +1,16 @@ shared: - where_you_will_train: - universities: - except_provider_codes: - - B31 - scitt_programmes: - except_provider_codes: - - E65 - higher_education: - except_provider_codes: - - B31 + placements: + provider_type: + universities: + except_provider_codes: + - B31 + program_type: + scitt_programmes: + except_provider_codes: + - E65 + higher_education: + except_provider_codes: + - B31 show_address: only_provider_codes: - 28T From b07291fedfddf14e37e0e117243c8106f2fb66cc Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Wed, 17 Jan 2024 10:34:08 +0000 Subject: [PATCH 08/10] Update CourseInformationController to use Config::CourseInformation --- .../publish/courses/course_information_controller.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/publish/courses/course_information_controller.rb b/app/controllers/publish/courses/course_information_controller.rb index 339a496d09..2382517dbd 100644 --- a/app/controllers/publish/courses/course_information_controller.rb +++ b/app/controllers/publish/courses/course_information_controller.rb @@ -61,21 +61,19 @@ def course_enrichment def param_form_key = :publish_course_information_form def course_information - @course_information ||= Rails.application.config_for('course_information').fetch(:where_you_will_train) + @course_information ||= Configs::CourseInformation.new(@course) end def show_scitt_guidance? return false unless @course.scitt_programme? - codes = course_information.dig(:scitt_programmes, :except_provider_codes) - codes.exclude?(@course.provider.provider_code) + course_information.placement(:program_type, :scitt_programmes) end def show_universities_guidance? return false unless @provider.university? - codes = course_information.dig(:universities, :except_provider_codes) - codes.exclude?(@course.provider.provider_code) + course_information.placement(:provider_type, :universities) end helper_method :show_scitt_guidance?, :show_universities_guidance? end From 8be482a40b6f891b0459c11adc23d23435c8a853 Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Wed, 17 Jan 2024 12:20:48 +0000 Subject: [PATCH 09/10] Add specs for Config::CourseInformation rename #placement to #show_placement_guidance? --- .../courses/about_schools_component/view.rb | 4 +- .../courses/course_information_controller.rb | 4 +- app/services/configs/course_information.rb | 2 +- .../configs/course_information_spec.rb | 158 ++++++++++++++++++ 4 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 spec/services/configs/course_information_spec.rb diff --git a/app/components/find/courses/about_schools_component/view.rb b/app/components/find/courses/about_schools_component/view.rb index 77faa82613..3f5fdae929 100644 --- a/app/components/find/courses/about_schools_component/view.rb +++ b/app/components/find/courses/about_schools_component/view.rb @@ -29,13 +29,13 @@ def render? def show_higher_education_guidance? return false unless course.higher_education_programme? - course_information_config.placement(:program_type, :higher_education) + course_information_config.show_placement_guidance?(:program_type, :higher_education) end def show_scitt_guidance? return false unless course.scitt_programme? - course_information_config.placement(:program_type, :scitt_programmes) + course_information_config.show_placement_guidance?(:program_type, :scitt_programmes) end private diff --git a/app/controllers/publish/courses/course_information_controller.rb b/app/controllers/publish/courses/course_information_controller.rb index 2382517dbd..1de5968703 100644 --- a/app/controllers/publish/courses/course_information_controller.rb +++ b/app/controllers/publish/courses/course_information_controller.rb @@ -67,13 +67,13 @@ def course_information def show_scitt_guidance? return false unless @course.scitt_programme? - course_information.placement(:program_type, :scitt_programmes) + course_information.show_placement_guidance?(:program_type, :scitt_programmes) end def show_universities_guidance? return false unless @provider.university? - course_information.placement(:provider_type, :universities) + course_information.show_placement_guidance?(:provider_type, :universities) end helper_method :show_scitt_guidance?, :show_universities_guidance? end diff --git a/app/services/configs/course_information.rb b/app/services/configs/course_information.rb index fe3487d934..6faa415dbb 100644 --- a/app/services/configs/course_information.rb +++ b/app/services/configs/course_information.rb @@ -7,7 +7,7 @@ def initialize(course) @course = course end - def placement(type, subtype) + def show_placement_guidance?(type, subtype) @db.dig(:placements, type, subtype, :except_provider_codes).exclude?(@course.provider.provider_code) end diff --git a/spec/services/configs/course_information_spec.rb b/spec/services/configs/course_information_spec.rb new file mode 100644 index 0000000000..2f27c74193 --- /dev/null +++ b/spec/services/configs/course_information_spec.rb @@ -0,0 +1,158 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Configs::CourseInformation do + let(:scitt_provider) { build(:provider, :scitt, provider_code:) } + let(:university_provider) { build(:provider, :university, provider_code:) } + + 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) + 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) + 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) + 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) + 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) + 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) + end + end + end + + describe '#contact_form?' do + let(:provider) { scitt_provider } + let(:course) { scitt_course } + + context 'when provider has a contact form' do + let(:provider_code) { 'U80' } + + it 'returns true' do + obj = described_class.new(course) + + expect(obj.contact_form?).to be(true) + end + end + + context 'when provider does not have a contact form' do + it 'returns false' do + obj = described_class.new(course) + + expect(obj.contact_form?).to be(false) + end + end + end + + describe '#contact_form' do + let(:provider) { scitt_provider } + let(:course) { scitt_course } + + context 'when provider has a contact form' do + let(:provider_code) { 'U80' } + + it 'returns the contact form URL' do + obj = described_class.new(course) + + expect(obj.contact_form).to eq('https://www.ucl.ac.uk/prospective-students/graduate/admissions-enquiries') + end + end + + context 'when provider does not have a contact form' do + it 'returns false' do + obj = described_class.new(course) + + expect(obj.contact_form).to be_nil + end + end + end + + describe '#show_address?' do + subject { described_class.new(course).show_address? } + + let(:provider) { scitt_provider } + let(:course) { scitt_course } + + context 'when course and provider codes exist' do + let(:provider_code) { '28T' } + let(:course_code) { 'X104' } + + it { is_expected.to be(true) } + end + + context 'when course and provider codes do not exist' do + it { is_expected.to be(false) } + end + end +end From e381d2433261fed8e4f928d442f6875242e903d5 Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Wed, 17 Jan 2024 12:33:41 +0000 Subject: [PATCH 10/10] Infer show placement subtype from the type --- .../courses/about_schools_component/view.rb | 4 ++-- .../courses/course_information_controller.rb | 8 ++------ app/services/configs/course_information.rb | 11 ++++++++-- config/course_information.yml | 6 +++--- .../configs/course_information_spec.rb | 20 ++++++------------- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/app/components/find/courses/about_schools_component/view.rb b/app/components/find/courses/about_schools_component/view.rb index 3f5fdae929..bb6c95512d 100644 --- a/app/components/find/courses/about_schools_component/view.rb +++ b/app/components/find/courses/about_schools_component/view.rb @@ -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 diff --git a/app/controllers/publish/courses/course_information_controller.rb b/app/controllers/publish/courses/course_information_controller.rb index 1de5968703..9859c9ebbf 100644 --- a/app/controllers/publish/courses/course_information_controller.rb +++ b/app/controllers/publish/courses/course_information_controller.rb @@ -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 diff --git a/app/services/configs/course_information.rb b/app/services/configs/course_information.rb index 6faa415dbb..92923b1923 100644 --- a/app/services/configs/course_information.rb +++ b/app/services/configs/course_information.rb @@ -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 diff --git a/config/course_information.yml b/config/course_information.yml index c7a4cfcc39..00ecb7b09f 100644 --- a/config/course_information.yml +++ b/config/course_information.yml @@ -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: diff --git a/spec/services/configs/course_information_spec.rb b/spec/services/configs/course_information_spec.rb index 2f27c74193..55537532cf 100644 --- a/spec/services/configs/course_information_spec.rb +++ b/spec/services/configs/course_information_spec.rb @@ -9,9 +9,6 @@ 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' } @@ -19,7 +16,6 @@ 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' } @@ -27,7 +23,7 @@ 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 @@ -35,32 +31,30 @@ 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 @@ -68,13 +62,12 @@ 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 @@ -82,12 +75,11 @@ 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