Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort qualifications by type and date #423

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/lib/qualifications_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def teacher(trn: nil)
endpoint,
{
include: %w[
HigherEducationQualifications
Induction
InitialTeacherTraining
NpqQualifications
Expand Down
46 changes: 20 additions & 26 deletions app/lib/qualifications_api/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ def name
def qualifications
@qualifications = []

add_eyts
add_induction
add_itt
add_mandatory_qualifications
add_npq
add_mandatory_qualifications
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given we can have multiple mandatory qualifications returned, do we need explicit ordering by awarded, as we do for NPQ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, I hadn't noticed these could be multiples, have applied the same date sorting as others now.

add_induction
add_qts
add_higher_education_qualifications
add_itt
add_eyts
add_itt(qts: false)

@qualifications
.flatten!
.sort_by! { |qualification| qualification.awarded_at || Date.new }
.reverse!
@qualifications.flatten!
end

def sanctions
Expand Down Expand Up @@ -66,6 +63,8 @@ def add_eyts
def add_npq
api_data
.fetch("npq_qualifications", [])
.sort_by { |npq| npq.awarded&.to_date }
.reverse
.each do |npq|
@qualifications << Qualification.new(
awarded_at: npq.awarded&.to_date,
Expand All @@ -76,9 +75,14 @@ def add_npq
end
end

def add_itt
@qualifications << api_data
.fetch("initial_teacher_training", [])
def add_itt(qts: true)
all_itt_data = api_data.fetch("initial_teacher_training", [])
eyts_itt_data, qts_itt_data = all_itt_data.partition { |itt| itt.programme_type.starts_with?("EYITT") }
itt_data = qts ? qts_itt_data : eyts_itt_data

@qualifications << itt_data
.sort_by { |itt| itt.awarded&.to_date }
.reverse
.map do |itt_response|
Qualification.new(
awarded_at: itt_response.end_date&.to_date,
Expand All @@ -104,7 +108,10 @@ def add_induction
def add_mandatory_qualifications
return if api_data.mandatory_qualifications.blank?

@qualifications << api_data.mandatory_qualifications.map do |mq|
@qualifications << api_data.mandatory_qualifications
.sort_by { |mq| mq.awarded&.to_date }
.reverse
.map do |mq|
Qualification.new(
awarded_at: mq.awarded&.to_date,
details: mq,
Expand All @@ -113,19 +120,6 @@ def add_mandatory_qualifications
)
end
end

def add_higher_education_qualifications
return if api_data.higher_education_qualifications.blank?

@qualifications << api_data.higher_education_qualifications.map do |heq|
Qualification.new(
awarded_at: heq.awarded&.to_date,
details: heq,
name: heq.name,
type: :higher_education
)
end
end
end

class CoercedDetails < Hash
Expand Down
57 changes: 29 additions & 28 deletions spec/lib/qualifications_api/teacher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@
]
},
"initialTeacherTraining" => [
{
"qualification" => {
"name" => "PGCE"
},
"startDate" => "2011-01-17",
"endDate" => "2012-02-2",
"programmeType" => "EYITTSchoolDirectEarlyYears",
"programmeTypeDescription" => "Early Years Initial Teacher Training (School Direct)",
"result" => "Pass",
"ageRange" => {
"description" => "3 to 7 years"
},
"provider" => {
"name" => "Earl Spencer Primary School",
"ukprn" => nil
},
"subjects" => [{ "code" => "100079", "name" => "business studies" }]
},
{
"qualification" => {
"name" => "BA"
Expand Down Expand Up @@ -76,13 +94,20 @@

it "sorts the qualifications in reverse chronological order by date of award" do
expect(qualifications.map(&:type)).to eq(
%i[NPQSL NPQML eyts qts induction mandatory itt]
%i[NPQSL NPQML mandatory induction qts itt eyts itt]
)
end

it "orders QTS ITT qualifications before EYTS ITT qualifications" do
itt_qualifications = qualifications.select { |q| q.type == :itt }
expect(itt_qualifications.map { |q| q.details.programme_type }).to eq(
%w[HEI EYITTSchoolDirectEarlyYears]
)
end

context "ITT result field" do
before do
api_data["initialTeacherTraining"][0]["result"] = "DeferredForSkillsTests"
api_data["initialTeacherTraining"].each { |itt| itt["result"] = "DeferredForSkillsTests" }
end

it "returns human readable values" do
Expand Down Expand Up @@ -150,8 +175,8 @@
}
end

it "sorts the qualifications in reverse chronological order by date of award" do
expect(qualifications.map(&:type)).to eq(%i[itt NPQML])
it "sorts the qualifications in reverse order by date of award and type" do
expect(qualifications.map(&:type)).to eq(%i[NPQML itt])
end
end

Expand Down Expand Up @@ -198,29 +223,5 @@
expect(qualifications.map(&:type)).to eq(%i[qts itt])
end
end

context "when a Higher Education qualification is returned" do
let(:api_data) do
{
"higherEducationQualifications" => [
{
"name" => "Some Qualification",
"awarded" => "2022-2-22",
"subjects" => [
{ "code" => "100079", "name" => "Business Studies" }
]
}
]
}
end

it "creates a qualification with the correct attributes" do
expect(qualifications.first).to have_attributes(
type: :higher_education,
name: "Some Qualification",
awarded_at: Date.parse("2022-2-22")
)
end
end
end
end