Skip to content

Commit

Permalink
Merge pull request #7293 from DFE-Digital/tighten-ventrus-ats-school-…
Browse files Browse the repository at this point in the history
…mapping

Fix Ventrus school mapping
  • Loading branch information
scruti authored Nov 19, 2024
2 parents 7cde35c + 06f4c65 commit 103e6b0
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
16 changes: 12 additions & 4 deletions app/services/vacancies/import/sources/ventrus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def self.source_name
def each
items.each do |item|
schools = find_schools(item)
next if schools.blank?
next if vacancy_listed_at_excluded_school_type?(schools)

v = Vacancy.find_or_initialize_by(
Expand Down Expand Up @@ -101,12 +102,19 @@ def organisation_fields(schools)
}
end

# All the vacancies in the feed must belong to Ventrus trust schools
def find_schools(item)
multi_academy_trust = SchoolGroup.trusts.find_by(uid: VENTRUS_TRUST_UID)
return [] if item["TrustUID"] != VENTRUS_TRUST_UID

multi_academy_trust&.schools&.where(urn: item["URN"]).presence ||
Organisation.where(urn: item["URN"]).presence ||
Array(multi_academy_trust)
multi_academy_trust = SchoolGroup.trusts.find_by(uid: item["TrustUID"])
return [] if multi_academy_trust.blank?

school_urns = item["URN"]&.split(",")
schools = Organisation.where(urn: school_urns) if school_urns.present?
return Array(multi_academy_trust) if schools.blank?

# When having both trust and schools, only return the schools that are in the trust if any. Otherwise, return the trust itself.
multi_academy_trust.schools.where(urn: school_urns).order(:created_at).presence || Array(multi_academy_trust)
end

def job_roles_for(item)
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/vacancy_sources/ventrus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<URN>111111</URN>
<Working_Patterns>part_time</Working_Patterns>
<Contract_Type>permanent</Contract_Type>
<TrustUID></TrustUID>
<TrustUID>4243</TrustUID>
<Documents>
<document>
<name><![CDATA[JD Grade C Generalist TA Secondary (App 2) Updated 15.12.2020.pdf]]></name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<URN>111111</URN>
<Working_Patterns>part_time</Working_Patterns>
<Contract_Type>parental_leave_cover</Contract_Type>
<TrustUID></TrustUID>
<TrustUID>4243</TrustUID>
<Documents>
<document>
<name><![CDATA[JD Grade C Generalist TA Secondary (App 2) Updated 15.12.2020.pdf]]></name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<URN>111111</URN>
<Working_Patterns>part_time</Working_Patterns>
<Contract_Type>permanent</Contract_Type>
<TrustUID></TrustUID>
<TrustUID>4243</TrustUID>
<Documents>
<document>
<name><![CDATA[JD Grade C Generalist TA Secondary (App 2) Updated 15.12.2020.pdf]]></name>
Expand Down
81 changes: 80 additions & 1 deletion spec/services/vacancies/import/sources/ventrus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,94 @@
end
end

context "when multiple school" do
context "when the vacancy is associated with multiple schools from the trust" do
let!(:school2) { create(:school, name: "Test School 2", urn: "222222", phase: :primary) }
let(:schools) { [school1, school2] }

let(:response_body) { super().gsub("111111", "111111,222222") }

it "assigns the vacancy to both schools" do
expect(vacancy.organisations).to contain_exactly(school1, school2)
end

it "assigns the vacancy job location to the central trust" do
expect(vacancy.readable_job_location).to eq(school1.name)
end
end

context "when the vacancy belongs to the central trust office instead of a particular/multiple school" do
let(:response_body) { super().gsub("111111", "") }

it "the vacancy is valid" do
expect(vacancy).to be_valid
end

it "assigns the vacancy to the school group" do
expect(vacancy.organisations).to contain_exactly(school_group)
end

it "assigns the vacancy job location to the school group" do
expect(vacancy.readable_job_location).to eq(school_group.name)
end
end

context "when the school doesn't belong to Ventrus school group" do
let(:school2) { create(:school, name: "Test School 2", urn: "222222", phase: :primary) }
let(:response_body) { super().gsub("111111", "222222") }

it "assigns the vacancy to the school group" do
expect(vacancy.organisations).to contain_exactly(school_group)
end

it "assigns the vacancy job location to the school group" do
expect(vacancy.readable_job_location).to eq(school_group.name)
end

context "when the school group is not provided" do
let(:response_body) { super().gsub("4243", "") }

it "does not import vacancy" do
expect(subject.count).to eq(0)
end
end

context "when the school group is different to Ventrus" do
let(:response_body) { super().gsub("4243", "4444") }

it "does not import vacancy" do
expect(subject.count).to eq(0)
end
end
end

context "when the school URN doesn't belong to any school" do
let(:response_body) { super().gsub("111111", "123456789") }

it "assigns the vacancy to the school group" do
expect(vacancy.organisations).to contain_exactly(school_group)
end

it "assigns the vacancy job location to the school group" do
expect(vacancy.readable_job_location).to eq(school_group.name)
end

context "when the school group is not provided" do
let(:response_body) { super().gsub("4243", "") }

it "does not import vacancy" do
expect(subject.count).to eq(0)
end
end

context "when the school group is different to Ventrus" do
let(:response_body) { super().gsub("4243", "4444") }

it "does not import vacancy" do
expect(subject.count).to eq(0)
end
end
end

context "when visa_sponsorship_available field is not supplied" do
let(:response_body) { file_fixture("vacancy_sources/ventrus_without_visa_sponsorship_available.xml").read }

Expand Down

0 comments on commit 103e6b0

Please sign in to comment.