Skip to content

Commit

Permalink
Merge pull request #2913 from DFE-Digital/CST-1207-ensure-that-mentor…
Browse files Browse the repository at this point in the history
…-pools-transfer-over-when-a-schools-gias-record-updates

CST-1207: rectify mentor pools when a participant is rectified
  • Loading branch information
ltello committed Jan 19, 2023
2 parents d32a7e5 + ead966b commit 1dfde2a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/services/data_stage/process_school_changes.rb
Expand Up @@ -98,7 +98,8 @@ def move_assets_from!(school:, successor:)
school_cohort.update!(school: successor)
school_cohort.ecf_participant_profiles.each do |profile|
RectifyParticipantSchool.call(participant_profile: profile,
school: successor,
from_school: school,
to_school: successor,
transfer_pupil_premium_and_sparsity: false)
end
end
Expand Down
42 changes: 28 additions & 14 deletions app/services/rectify_participant_school.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true

class RectifyParticipantSchool < BaseService
attr_reader :participant_profile, :school, :transfer_pupil_premium_and_sparsity
attr_reader :participant_profile, :from_school, :to_school, :transfer_pupil_premium_and_sparsity, :cohort, :school_cohort

def initialize(participant_profile:, school:, transfer_pupil_premium_and_sparsity: true)
def initialize(participant_profile:, from_school:, to_school:, transfer_pupil_premium_and_sparsity: true)
@participant_profile = participant_profile
@school = school
@from_school = from_school
@to_school = to_school
@transfer_pupil_premium_and_sparsity = transfer_pupil_premium_and_sparsity
end

Expand All @@ -14,22 +15,35 @@ def initialize(participant_profile:, school:, transfer_pupil_premium_and_sparsit
# that have been added to the wrong school by mistake or in a GIAS school closure/reopen
# scenario.
def call
cohort = participant_profile.school_cohort.cohort
school_cohort = school.school_cohorts.find_by(cohort:)
@cohort = participant_profile.school_cohort.cohort
@school_cohort = to_school.school_cohorts.find_by(cohort:)
return if school_cohort.blank?

ActiveRecord::Base.transaction do
participant_profile.teacher_profile.update!(school:)
attrs = {
school_cohort:,
}
rectify_teacher_profile
rectify_mentor_pools if participant_profile.mentor?
rectify_participant_profile
end
end

private

def rectify_mentor_pools
from_school.school_mentors.find_by(participant_profile:)&.update!(school: to_school)
end

if transfer_pupil_premium_and_sparsity
attrs[:sparsity_uplift] = school.sparsity_uplift?(cohort.start_year)
attrs[:pupil_premium_uplift] = school.pupil_premium_uplift?(cohort.start_year)
end
def rectify_participant_profile
attrs = { school_cohort: }

participant_profile.update!(attrs)
if transfer_pupil_premium_and_sparsity
attrs[:sparsity_uplift] = to_school.sparsity_uplift?(cohort.start_year)
attrs[:pupil_premium_uplift] = to_school.pupil_premium_uplift?(cohort.start_year)
end

participant_profile.update!(attrs)
end

def rectify_teacher_profile
participant_profile.teacher_profile.update!(school: to_school)
end
end
20 changes: 19 additions & 1 deletion spec/services/rectify_participant_school_spec.rb
Expand Up @@ -6,13 +6,22 @@
subject(:service) { described_class }
let(:cohort) { Cohort.current || create(:cohort, :current) }
let(:participant_profile) { create(:ect_participant_profile, cohort:) }
let(:participant_identity) { participant_profile.participant_identity }
let(:old_school) { participant_profile.school }
let(:new_school) { create(:school, name: "Big Shiny School", urn: "123000") }
let!(:school_cohort) { create(:school_cohort, cohort:, school: new_school) }
let(:transfer_uplift) { true }

describe ".call" do
before do
service.call(participant_profile:, school: new_school, transfer_pupil_premium_and_sparsity: transfer_uplift)
if participant_profile.mentor?
old_school.school_mentors.create!(participant_profile:, preferred_identity: participant_identity)
end

service.call(participant_profile:,
from_school: old_school,
to_school: new_school,
transfer_pupil_premium_and_sparsity: transfer_uplift)
participant_profile.reload
end

Expand Down Expand Up @@ -65,5 +74,14 @@
expect(participant_profile).not_to be_sparsity_uplift
end
end

context "when the participant is a mentor" do
let(:participant_profile) { create(:mentor_participant_profile) }

it "update both schools' mentor pool" do
expect(old_school.mentor_profiles).not_to include(participant_profile)
expect(new_school.mentor_profiles).to include(participant_profile)
end
end
end
end

0 comments on commit 1dfde2a

Please sign in to comment.