Skip to content

Commit

Permalink
[CPDLP-3632] Overrides application ukprn from schools table when the …
Browse files Browse the repository at this point in the history
…school ukprn pulled in from ECF is nil
  • Loading branch information
leandroalemao committed Oct 21, 2024
1 parent 258b481 commit 0282a31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/services/migration/migrators/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ def call
if ecf_npq_application.school_urn.present?
application.school_id = find_school_id!(urn: ecf_npq_application.school_urn)

if application.school.ukprn.to_s == ecf_npq_application.school_ukprn.to_s
if ecf_npq_application.school_ukprn && ecf_npq_application.school_ukprn.to_s == application.school.ukprn.to_s
application.ukprn = ecf_npq_application.school_ukprn
elsif ecf_npq_application.school_ukprn.blank?
application.ukprn = application.school.ukprn
else
ecf_npq_application.errors.add(:base, "School UKPRN does not match")
raise ActiveRecord::RecordInvalid, ecf_npq_application
Expand Down
13 changes: 13 additions & 0 deletions spec/services/migration/migrators/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ def setup_failure_state
expect(failure_manager).to have_received(:record_failure).once.with(ecf_resource1, /Validation failed: School UKPRN does not match/)
end
end

context "when the school ukprn pulled in from ECF is nil" do
before { ecf_resource1.update!(school_ukprn: nil) }

it "overrides ukprn from Schools table on the NPQ application" do
application = Application.find_by!(ecf_id: ecf_resource1.id)
expect(application.ukprn).to be_nil

instance.call

expect(application.reload.ukprn).to eq(application.school.ukprn)
end
end
end
end
end

0 comments on commit 0282a31

Please sign in to comment.