Skip to content

Commit

Permalink
Change sites to schools
Browse files Browse the repository at this point in the history
  add test for copying schools
  • Loading branch information
inulty-dfe committed Dec 6, 2024
1 parent 75eb78d commit 6f006a7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 5 additions & 10 deletions app/views/support/providers/copy_courses/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<h1 class="govuk-heading-l">Copy courses from:</h1>
<h1 class="govuk-heading-l"><%= @provider.provider_name %></h1>
<h2 class="govuk-heading-m">Copy courses from:</h2>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<div>
<%= form_with url: support_recruitment_cycle_provider_copy_courses_path(@recruitment_cycle.year, @provider) do |form| %>
<% error = flash[:error] && flash[:error]["message"] == "Name or provider code" %>
<div class="govuk-form-group<% if error %> govuk-form-group--error<% end %>">
<%= form.label :query, { class: "govuk-label", for: "provider" } do %>
Search for an organisation to copy courses from
<div>Search for an organisation to copy courses from:</div>
<span class="govuk-hint govuk-!-display-inline">Enter the name or provider code</span>
<% if error %>
<span class="govuk-error-message" id="provider-error" data-qa="provider-error">
Expand All @@ -25,17 +26,11 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-form-group">
<%= form.govuk_check_box :sites, true, false, label: { text: "Copy study sites?" }, multiple: false %>
</div>
</div>
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-form-group">
<%= 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 %>
</div>
</div>
</div>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form.govuk_submit "Continue" %>
Expand Down
41 changes: 41 additions & 0 deletions spec/requests/support/copy_courses_spec.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 4 additions & 6 deletions spec/system/support/providers/copy_courses_to_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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|
Expand Down

0 comments on commit 6f006a7

Please sign in to comment.