Skip to content

Commit

Permalink
CST-2540: get induction start date from DQT induction periods
Browse files Browse the repository at this point in the history
  • Loading branch information
ltello committed Apr 30, 2024
1 parent 90e1b8b commit 7aa0d47
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 38 deletions.
11 changes: 10 additions & 1 deletion app/presenters/dqt_record_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ def qts_date
dqt_record.dig("qualified_teacher_status", "qts_date")
end

# This is a patch until we migrate this presenter from DQT::V1 to DQT::V3
# The "induction", "start_date" coming in DQT::V1 is not the more accurate one so,
# either we get it from the "induction" "periods" coming V1 or V3
def induction_start_date
dqt_record.dig("induction", "start_date")
@induction_start_date ||= (
dqt_record.dig("periods") ||
FullDQT::V3::Client.new.get_record(trn:)&.dig("induction", "periods")
).to_a
.map { |period| period["startDate"] }
.compact
.min
end

def induction_completion_date
Expand Down
12 changes: 7 additions & 5 deletions app/services/dqt_record_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def initialize(trn:, full_name:, date_of_birth:, nino: nil, check_first_name_onl
@check_first_name_only = check_first_name_only
end

def dqt_record(trn, nino)
full_dqt_client.get_record(trn:, birthdate: date_of_birth, nino:)
def dqt_record(trn)
full_dqt_client.get_record(trn:)
end

def full_dqt_client
@full_dqt_client ||= FullDQT::V1::Client.new
@full_dqt_client ||= FullDQT::V3::Client.new
end

def check_record
Expand All @@ -48,7 +48,7 @@ def check_record
@trn = "0000001" if trn.blank?

padded_trn = TeacherReferenceNumber.new(trn).formatted_trn
dqt_record = DQTRecordPresenter.new(dqt_record(padded_trn, nino))
dqt_record = DQTRecordPresenter.new(dqt_record(padded_trn))

return check_failure(:no_match_found) if dqt_record.blank?
return check_failure(:found_but_not_active) unless dqt_record.active?
Expand Down Expand Up @@ -151,7 +151,9 @@ def magic_dqt_record(with_induction: true, active_alert: false, qts_date: 2.year

if with_induction
record.merge!("induction" => {
"start_date" => induction_start_date,
"periods" => [
{ "start_date" => induction_start_date }
],
"status" => "In Progress",
})
end
Expand Down
17 changes: 11 additions & 6 deletions app/services/participants/check_and_set_completion_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ def completion_date
induction&.fetch("endDate", nil)
end

def start_date
induction&.fetch("startDate", nil)
def induction
@induction ||= DQT::GetInductionRecord.call(trn: participant_profile.teacher_profile.trn)
end

def participant_start_date
participant_profile.induction_start_date
def induction_periods
Array(induction&.dig("periods"))
end

def induction
@induction ||= DQT::GetInductionRecord.call(trn: participant_profile.teacher_profile.trn)
def participant_start_date
participant_profile.induction_start_date
end

def record_start_date_inconsistency
Expand All @@ -42,5 +42,10 @@ def record_start_date_inconsistency
},
)
end

# returns the minimum start date of all the induction periods
def start_date
@start_date ||= induction_periods.map { |period| period["startDate"] }.compact.min
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def valid_dqt_response
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction_start_date" => Date.new(2022, 9, 1),
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def valid_dqt_response
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction_start_date" => induction_start_date.to_date,
"induction" => {
"start_date" => induction_start_date,
"periods" => [{ "start_date" => induction_start_date }],
"status" => "Active",
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def valid_dqt_response
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction_start_date" => induction_start_date.to_date,
"induction" => {
"start_date" => induction_start_date,
"periods" => [{ "start_date" => induction_start_date }],
"status" => "Active",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def valid_dqt_response(participant_data)
"dob" => participant_data[:date_of_birth],
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def valid_dqt_response(participant_data)
"dob" => participant_data[:date_of_birth],
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def valid_dqt_response(participant_data)
"dob" => participant_data[:date_of_birth],
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def valid_dqt_response(participant_data)
"dob" => participant_data[:date_of_birth],
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def valid_dqt_response(participant_data)
"dob" => participant_data[:date_of_birth],
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def valid_dqt_response(participant_data)
"dob" => participant_data[:date_of_birth],
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def valid_dqt_response(participant_data)
"dob" => participant_data[:date_of_birth],
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ def valid_dqt_response(participant_data)
"dob" => participant_data[:date_of_birth],
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
})
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/admin/participants/validate_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"qts_date": "2021-07-05T00:00:00Z",
},
"induction": {
"start_date": "2021-09-02T00:00:00Z",
"periods" => [{ "start_date" => "2021-09-02T00:00:00Z" }],
},
})
end
Expand Down Expand Up @@ -95,8 +95,8 @@
"qts_date": "2021-07-05T00:00:00Z",
},
"induction": {
"start_date": "2021-09-02T00:00:00Z",
},
"periods" => [{ "start_date" => "2021-09-02T00:00:00Z" }],
},
})
end

Expand Down
18 changes: 9 additions & 9 deletions spec/services/participant_validation_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
context "when the participant has previously had an induction" do
let(:induction) do
{
"start_date" => induction_start_date,
"periods" => [{ "start_date" => induction_start_date }],
"completion_date" => induction_completion_date,
"status" => "Pass",
"state" => 0,
Expand All @@ -238,7 +238,7 @@
context "when the participant has an induction with nil start_date" do
let(:induction) do
{
"start_date" => nil,
"periods" => [{ "start_date" => nil }],
}
end

Expand All @@ -262,7 +262,7 @@
context "when the participant's induction status is InProgress" do
let(:induction) do
{
"start_date" => induction_start_date,
"periods" => [{ "start_date" => induction_start_date }],
"status" => "InProgress",
}
end
Expand All @@ -287,7 +287,7 @@
context "when the participant's induction status is Not Yet Completed" do
let(:induction) do
{
"start_date" => induction_start_date,
"periods" => [{ "start_date" => induction_start_date }],
"status" => "Not Yet Completed",
}
end
Expand All @@ -313,7 +313,7 @@
let!(:eligibility) { create(:ineligible_participant, trn:, reason: :previous_participation) }
let(:induction) do
{
"start_date" => induction_start_date,
"periods" => [{ "start_date" => induction_start_date }],
"completion_date" => induction_completion_date,
"status" => "Pass",
"state" => 0,
Expand All @@ -331,7 +331,7 @@
let(:induction_completion_date) { nil }
let(:induction) do
{
"start_date" => induction_start_date,
"periods" => [{ "start_date" => induction_start_date }],
"completion_date" => induction_completion_date,
"status" => "Pass",
"state" => 0,
Expand All @@ -349,7 +349,7 @@
let(:induction_completion_date) { nil }
let(:induction) do
{
"start_date" => induction_start_date,
"periods" => [{ "start_date" => induction_start_date }],
"completion_date" => induction_completion_date,
"status" => "Pass",
"state" => 0,
Expand All @@ -367,7 +367,7 @@
let(:induction_completion_date) { nil }
let(:induction) do
{
"start_date" => induction_start_date,
"periods" => [{ "start_date" => induction_start_date }],
"completion_date" => induction_completion_date,
"status" => "Pass",
"state" => 0,
Expand All @@ -383,7 +383,7 @@
context "when the participant has an induction with the status of 'Exempt'" do
let(:induction) do
{
"start_date" => nil,
"periods" => [{ "start_date" => nil }],
"completion_date" => nil,
"status" => "Exempt",
"state" => 0,
Expand Down
13 changes: 12 additions & 1 deletion spec/services/participants/check_and_set_completion_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
let(:completion_date) { 1.month.ago.to_date }
let(:start_date) { 2.months.ago.to_date }
let(:induction_start_date) { start_date }
let(:dqt_induction_record) { { "endDate" => completion_date, "startDate" => start_date } }
let(:dqt_induction_record) do
{ "endDate" => completion_date,
"periods" => [
{ "startDate" => start_date,
"endDate" => start_date + 1.week,
},
{ "startDate" => start_date + 1.week,
"endDate" => start_date + 2.weeks,
},
]
}
end

subject(:service_call) { described_class.call(participant_profile:) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def setup_response_from_dqt(participant_name, dob, trn)
"qts_date": "2021-07-05T00:00:00Z",
},
"induction": {
"start_date": "2021-09-02T00:00:00Z",
"periods" => [{ "start_date" => "2021-09-02T00:00:00Z" }],
},
}), headers: {})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def and_sit_reported_participant(sit_name, participant_name, participant_trn, pa
"dob" => participant_dob,
"qualified_teacher_status" => { "qts_date" => 1.year.ago },
"induction" => {
"start_date" => 1.month.ago,
"periods" => [{ "start_date" => 1.month.ago }],
"status" => "Active",
},
},
Expand Down

0 comments on commit 7aa0d47

Please sign in to comment.