diff --git a/app/controllers/support/providers/copy_courses_controller.rb b/app/controllers/support/providers/copy_courses_controller.rb index 9379ab4ea4..35a2308117 100644 --- a/app/controllers/support/providers/copy_courses_controller.rb +++ b/app/controllers/support/providers/copy_courses_controller.rb @@ -12,7 +12,7 @@ def create @provider = Provider.find(params[:provider_id]) @from_provider = recruitment_cycle.providers.find_by(provider_code: params[:course][:autocompleted_provider_code]) - sites_copy_to_course = params[:sites] ? Sites::CopyToCourseService : ->(*) {} + sites_copy_to_course = params[:schools] ? Sites::CopyToCourseService : ->(*) {} copier = ::Courses::CopyToProviderService.new(sites_copy_to_course:, enrichments_copy_to_course: Enrichments::CopyToCourseService.new, force: true) diff --git a/app/views/support/providers/copy_courses/new.html.erb b/app/views/support/providers/copy_courses/new.html.erb index 5323ca9fb3..05ff42a383 100644 --- a/app/views/support/providers/copy_courses/new.html.erb +++ b/app/views/support/providers/copy_courses/new.html.erb @@ -1,4 +1,5 @@ -

Copy courses from:

+

<%= @provider.provider_name %>

+

Copy courses from:

@@ -6,7 +7,7 @@ <% error = flash[:error] && flash[:error]["message"] == "Name or provider code" %>
<%= form.label :query, { class: "govuk-label", for: "provider" } do %> - Search for an organisation to copy courses from +
Search for an organisation to copy courses from:
Enter the name or provider code <% if error %> @@ -25,17 +26,11 @@
- <%= form.govuk_check_box :sites, true, false, label: { text: "Copy study sites?" }, multiple: false %> -
-
-
-
-
-
- <%= form.govuk_check_box :schools, true, false, label: { text: "Copy placement schools?" }, multiple: false %> + <%= form.govuk_check_box :schools, true, false, label: { text: "Copy placement schools?" }, hint: { text: tag.div("Any placement schools that are not already linked to the target provider will not be copied", class: %w[govuk-hint govuk-!-font-size-16]) }, multiple: false %>
+
<%= form.govuk_submit "Continue" %> diff --git a/spec/requests/support/copy_courses_spec.rb b/spec/requests/support/copy_courses_spec.rb new file mode 100644 index 0000000000..4b17515d1d --- /dev/null +++ b/spec/requests/support/copy_courses_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Support::CopyCourses' do + include DfESignInUserHelper + let(:user) { create(:user, :admin) } + let(:source_provider) { create(:provider, courses: create_list(:course, 3, :with_full_time_sites)) } + let!(:target_provider) { create(:provider, sites: source_provider.courses.flat_map(&:sites)) } + let!(:year) { find_or_create(:recruitment_cycle).year } + + before { host! URI(Settings.base_url).host } + + describe 'GET new' do + it 'responds with 200' do + login_user(user) + get "/support/2025/providers/#{source_provider.id}/copy_courses/new" + expect(response).to have_http_status(:ok) + end + end + + describe 'POST create' do + context 'with schools' do + it 'copies the courses with schools' do + login_user(user) + post "/support/#{year}/providers/#{target_provider.id}/copy_courses", params: { 'course[autocompleted_provider_code]' => source_provider.provider_code, schools: '1' } + expect(target_provider.reload.courses.length).to eq(3) + courses = target_provider.reload.courses + expect(courses.flat_map(&:sites).length).to eq(3) + end + end + + context 'without schools' do + it 'copies the course without schools' do + login_user(user) + post "/support/#{year}/providers/#{target_provider.id}/copy_courses", params: { 'course[autocompleted_provider_code]' => source_provider.provider_code } + expect(target_provider.reload.courses.length).to eq(3) + end + end + end +end diff --git a/spec/system/support/providers/copy_courses_to_provider_spec.rb b/spec/system/support/providers/copy_courses_to_provider_spec.rb index 84ca8b0605..d2bde1704a 100644 --- a/spec/system/support/providers/copy_courses_to_provider_spec.rb +++ b/spec/system/support/providers/copy_courses_to_provider_spec.rb @@ -12,17 +12,15 @@ create(:course, :withdrawn, :with_full_time_sites) ] end - let(:source_provider) { create(:provider, provider_name: 'Source Provider', courses:) } - let(:target_provider) { create(:provider, provider_name: 'Target Provider') } + let!(:source_provider) { create(:provider, provider_name: 'Source Provider', courses:) } + let!(:target_provider) { create(:provider, provider_name: 'Target Provider') } let(:user) { create(:user, :admin) } before do sign_in_system_test(user:) - source_provider - target_provider end - it 'copy courses from one provider to another', :js_browser do + it 'copy courses from one provider to another', :js do visit '/support' click_on 'Target Provider' click_on 'Copy Courses' @@ -31,7 +29,7 @@ sleep 3 li = page.find('ul#provider__listbox li', visible: false) li.click - page.find_by_id('sites-true-field', visible: false).click + page.find_by_id('schools-true-field', visible: false).click click_on 'Continue' click_on 'Courses' courses.map(&:name).each do |course_name|