diff --git a/app/helpers/view_helper.rb b/app/helpers/view_helper.rb index 77d3624254..21a8be2563 100644 --- a/app/helpers/view_helper.rb +++ b/app/helpers/view_helper.rb @@ -47,6 +47,7 @@ def title_with_error_prefix(title, error) def enrichment_error_url(provider_code:, course:, field:, message: nil) base = "/publish/organisations/#{provider_code}/#{course.recruitment_cycle_year}/courses/#{course.course_code}" provider_base = "/publish/organisations/#{provider_code}/#{course.recruitment_cycle_year}" + accrediting_provider = Settings.features.provider_partnerships ? ratifying_provider_publish_provider_recruitment_cycle_course_path(course.provider_code, course.recruitment_cycle_year, course.course_code) : accredited_provider_publish_provider_recruitment_cycle_course_path(course.provider_code, course.recruitment_cycle_year, course.course_code) if field.to_sym == :base base_errors_hash(provider_code, course)[message] @@ -62,7 +63,7 @@ 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:, applications_open_from: "#{base}/applications-open", a_level_subject_requirements: publish_provider_recruitment_cycle_course_a_levels_what_a_level_is_required_path( course.provider_code, diff --git a/app/models/concerns/publish/course_basic_detail_concern.rb b/app/models/concerns/publish/course_basic_detail_concern.rb index 4c3899ef33..7bcf350848 100644 --- a/app/models/concerns/publish/course_basic_detail_concern.rb +++ b/app/models/concerns/publish/course_basic_detail_concern.rb @@ -207,8 +207,12 @@ def course_creation_path_for(page) end when :applications_open new_publish_provider_recruitment_cycle_courses_applications_open_path(path_params) - when :accredited_provider - new_publish_provider_recruitment_cycle_courses_accredited_provider_path(path_params) + when :accredited_provider, :ratifying_provider + if Settings.features.provider_partnerships + new_publish_provider_recruitment_cycle_courses_ratifying_provider_path(path_params) + else + new_publish_provider_recruitment_cycle_courses_accredited_provider_path(path_params) + end when :can_sponsor_student_visa new_publish_provider_recruitment_cycle_courses_student_visa_sponsorship_path(path_params) when :can_sponsor_skilled_worker_visa diff --git a/app/models/provider.rb b/app/models/provider.rb index c2a733684e..ec40bb31e0 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -339,6 +339,8 @@ def accredited_body(provider_code) end def accredited_bodies + return accredited_partners if Settings.features.provider_partnerships + accrediting_provider_enrichments&.filter_map do |accrediting_provider_enrichment| provider_code = accrediting_provider_enrichment.UcasProviderCode diff --git a/app/views/publish/courses/ratifying_provider/new.html.erb b/app/views/publish/courses/ratifying_provider/new.html.erb index 163b73fca3..9d998b6a21 100644 --- a/app/views/publish/courses/ratifying_provider/new.html.erb +++ b/app/views/publish/courses/ratifying_provider/new.html.erb @@ -1,4 +1,4 @@ -<% content_for :page_title, title_with_error_prefix("Accredited provider – #{course.name_and_code}", @errors && @errors.any?) %> +<% content_for :page_title, title_with_error_prefix("Ratifying provider – #{course.name_and_code}", @errors && @errors.any?) %> <% content_for :before_content do %> <%= govuk_back_link_to(@back_link_path) %> @@ -14,7 +14,7 @@

<%= render CaptionText.new(text: t("course.add_course")) %> - Accredited provider + Ratifying provider

<%= render "publish/shared/error_messages", error_keys: [:accredited_provider_code] %> diff --git a/spec/features/publish/courses/add_ratifying_provider_when_publishing_a_course_spec.rb b/spec/features/publish/courses/add_ratifying_provider_when_publishing_a_course_spec.rb new file mode 100644 index 0000000000..2f8a7a9305 --- /dev/null +++ b/spec/features/publish/courses/add_ratifying_provider_when_publishing_a_course_spec.rb @@ -0,0 +1,170 @@ +# frozen_string_literal: true + +require 'rails_helper' + +feature 'Publishing a course when course accrediting provider is invalid', { can_edit_current_and_next_cycles: false } do + before do + allow(Settings.features).to receive(:provider_partnerships).and_return(true) + given_i_am_authenticated_as_a_provider_user + end + + scenario 'Add accrediting provider to provider and provider has no accrediting providers, change accrediting provider of course then publish' do + and_the_provider_has_no_accredited_provider + and_there_is_a_draft_course_with_an_unaccredited_provider + + # Publising is invalid + when_i_visit_the_course_page + and_i_click_the_publish_button + then_i_should_see_an_error_message_that_accredited_provider_is_not_accredited + + # Add accrediting provider to provider + when_i_click_the_error_message_link + then_it_takes_me_to_the_accredited_providers_page + when_i_click_add_an_accredited_provider + and_i_search_for_an_accredited_provider + and_i_fill_in_the_accredited_provider_form + and_i_confirm_creation_of_the_accredited_provider + then_i_see_that_the_accredited_provider_has_been_added + + # Publishing is invalid + when_i_visit_the_course_page + and_i_click_the_publish_button + then_i_should_see_an_error_message_that_accredited_provider_is_not_accredited + + # Clicking error message allows user to select accrediting provider + when_i_click_the_error_message_link + and_i_choose_the_new_accredited_provider + and_i_click_the_publish_button + then_i_should_see_a_success_message + end + + scenario 'Select valid accrediting provider to course and publish' do + and_the_provider_has_a_valid_accrediting_provider + and_there_is_a_draft_course_without_accrediting_provider + and_an_accredited_provider_exists + + # Publising is invalid + when_i_visit_the_course_page + and_i_click_the_publish_button + then_i_should_see_an_error_message_for_the_accrediting_provider + + # Clicking error message allows user to select accrediting provider + when_i_click_the_select_accredited_provider_error_message_link + and_i_choose_the_new_accredited_provider + and_i_click_the_publish_button + then_i_should_see_a_success_message + end + + def given_i_am_authenticated_as_a_provider_user + @user = create(:user, :with_provider) + given_i_am_authenticated(user: @user) + end + + def and_the_provider_has_a_valid_accrediting_provider + provider = @user.providers.first + provider.accredited_partnerships.create(accredited_provider:accredited_provider, description: 'Description') + end + + def and_the_provider_has_no_accredited_provider + expect(provider.accredited_providers).to be_empty + end + + def and_there_is_a_draft_course_without_accrediting_provider + given_a_course_exists( + :with_gcse_equivalency, + enrichments: [create(:course_enrichment, :initial_draft)], + sites: [create(:site, location_name: 'location 1')], + study_sites: [create(:site, :study_site)] + ) + end + + def and_there_is_a_draft_course_with_an_unaccredited_provider + given_a_course_exists( + :with_gcse_equivalency, + accrediting_provider: provider, + enrichments: [create(:course_enrichment, :initial_draft)], + sites: [create(:site, location_name: 'location 1')], + study_sites: [create(:site, :study_site)] + ) + end + + def when_i_visit_the_course_page + publish_provider_courses_show_page.load( + provider_code: provider.provider_code, + recruitment_cycle_year: provider.recruitment_cycle_year, + course_code: course.course_code + ) + end + + def then_i_should_see_a_success_message + expect(page).to have_content('Your course has been published.') + end + + def then_i_should_see_an_error_message_that_accredited_provider_is_not_accredited + expect(publish_provider_courses_show_page.error_messages).to include('Update the accredited provider') + end + + def then_i_should_see_an_error_message_for_the_accrediting_provider + expect(publish_provider_courses_show_page.error_messages).to include('Select an accredited provider') + end + + def when_i_click_the_error_message_link + publish_provider_courses_show_page.errors.first.link.click + end + + def then_it_takes_me_to_the_accredited_providers_page + expect(publish_courses_ratifying_providers_page).to be_displayed + end + + def when_i_click_add_an_accredited_provider + publish_courses_accredited_providers_page.add_new_link.click + expect(publish_provider_accredited_providers_search_page).to be_displayed + end + + def and_i_search_for_an_accredited_provider + publish_provider_accredited_providers_search_page.search_input.set(accredited_provider.provider_name) + publish_provider_accredited_providers_search_page.continue_button.click + choose accredited_provider.name_and_code + publish_provider_accredited_providers_search_page.continue_button.click + end + + def and_i_fill_in_the_accredited_provider_form + publish_courses_new_accredited_provider_page.about_section_input.set('About course') + + publish_courses_new_accredited_provider_page.submit.click + end + + def and_i_confirm_creation_of_the_accredited_provider + publish_courses_new_accredited_provider_page.submit.click + end + + def then_i_see_that_the_accredited_provider_has_been_added + expect(page).to have_content('Accredited partnership added') + end + + def and_i_click_the_publish_button + publish_provider_courses_show_page.publish_button.click + end + + def when_i_click_the_select_accredited_provider_error_message_link + page.click_link_or_button('Select an accredited provider') + end + + def and_i_choose_the_new_accredited_provider + choose accredited_provider.provider_name + page.click_link_or_button('Update ratifying partner') + expect(page).to have_content('Accredited provider updated') + end + + def and_an_accredited_provider_exists + accredited_provider + end + + def accredited_provider + @accredited_provider ||= create(:provider, :accredited_provider) + end + + def provider + @current_user.providers.first + end +end diff --git a/spec/features/publish/courses/new_schools_provider_partnerships_spec.rb b/spec/features/publish/courses/new_schools_provider_partnerships_spec.rb new file mode 100644 index 0000000000..6baf9685fa --- /dev/null +++ b/spec/features/publish/courses/new_schools_provider_partnerships_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'rails_helper' + +feature 'selection schools', { can_edit_current_and_next_cycles: false } do + before do + allow(Settings.features).to receive(:provider_partnerships).and_return(true) + given_i_am_authenticated_as_a_provider_user + and_that_sites_exist + when_i_visit_the_publish_courses_new_schools_page + end + + scenario 'selecting multiple schools' do + when_i_select_a_school + and_i_click_continue + then_i_am_met_with_the_accredited_provider_page + end + + scenario 'invalid entries' do + and_i_click_continue + then_i_am_met_with_errors + end + + private + + def given_i_am_authenticated_as_a_provider_user + @user = create(:user, :with_provider) + given_i_am_authenticated(user: @user) + end + + def and_that_sites_exist + provider.sites << create_list(:site, 3) + end + + def when_i_visit_the_publish_courses_new_schools_page + publish_courses_new_schools_page.load(provider_code: provider.provider_code, recruitment_cycle_year: Settings.current_recruitment_cycle_year, query: schools_params) + end + + def when_i_select_a_school + publish_courses_new_schools_page.check(provider.sites.first.location_name) + publish_courses_new_schools_page.check(provider.sites.second.location_name) + end + + def and_i_click_continue + publish_courses_new_schools_page.continue.click + end + + def provider + @provider ||= @user.providers.first + end + + def then_i_am_met_with_the_accredited_provider_page + expect(page).to have_current_path("/publish/organisations/#{provider.provider_code}/#{Settings.current_recruitment_cycle_year}/courses/ratifying-provider/new", ignore_query: true) + expect(page).to have_content('Ratifying provider') + end + + def then_i_am_met_with_errors + expect(page).to have_content('There is a problem') + expect(page).to have_content('Select at least one school') + end +end diff --git a/spec/support/page_objects/publish/courses/ratifying_providers.rb b/spec/support/page_objects/publish/courses/ratifying_providers.rb new file mode 100644 index 0000000000..b3f4ebeadc --- /dev/null +++ b/spec/support/page_objects/publish/courses/ratifying_providers.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module PageObjects + module Publish + module Courses + class RatifyingProviders < PageObjects::Base + set_url '/publish/organisations/{provider_code}/{recruitment_cycle_year}/courses/{course_code}/ratifying-provider' + + elements :suggested_accredited_bodies, '[data-qa="course__accredited_provider_option"]' + element :add_new_link, '[data-qa="course__add"]' + + element :update_button, 'input[type=submit]' + end + end + end +end