Skip to content

Commit

Permalink
make TSLR has_student_loan and student_loan_plan the same as other jo…
Browse files Browse the repository at this point in the history
…urneys
  • Loading branch information
alkesh committed Sep 23, 2024
1 parent 8c9faa6 commit afc065e
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 50 deletions.
16 changes: 3 additions & 13 deletions app/models/claim_student_loan_details_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ def initialize(claim)

def update_claim_with_latest_data
claim.transaction do
if claim.has_tslr_policy?
eligibility.update!(eligibility_student_loan_attributes)
claim.assign_attributes(claim_student_loans_policy_student_loan_attributes)
else
claim.assign_attributes(claim_student_loan_attributes)
end
eligibility.update!(eligibility_student_loan_attributes) if claim.has_tslr_policy?

claim.assign_attributes(claim_student_loan_attributes)

claim.save!(context: :"student-loan")
end
Expand All @@ -41,13 +38,6 @@ def claim_student_loan_attributes
}
end

def claim_student_loans_policy_student_loan_attributes
{
has_student_loan: student_loans_data.has_student_loan_for_student_loan_policy,
student_loan_plan: student_loans_data.student_loan_plan_for_student_loan_policy
}
end

def student_loans_data
@student_loans_data ||= StudentLoansDataPresenter.new(
national_insurance_number: national_insurance_number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ module TeacherStudentLoanReimbursement
class AnswersStudentLoansDetailsUpdater < Journeys::AnswersStudentLoansDetailsUpdater
def save!
journey_session.answers.assign_attributes(
student_loan_repayment_amount: student_loans_data.total_repayment_amount,
has_student_loan: student_loans_data.has_student_loan_for_student_loan_policy,
student_loan_plan: student_loans_data.student_loan_plan_for_student_loan_policy,
submitted_using_slc_data: student_loans_data.found_data?
student_loan_repayment_amount: student_loans_data.total_repayment_amount
)

journey_session.save!
rescue => e
Rollbar.error(e)
super
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def not_taught_enough?
answers.mostly_performed_leadership_duties == true
end

# checks two scenarios: (1) they do not have a student loan, (2) they have a student loan but the repayment amount is zero
def made_zero_repayments?
return true if answers.has_student_loan == false

answers.has_student_loan == true && answers.student_loan_repayment_amount == 0
end
end
Expand Down
11 changes: 0 additions & 11 deletions app/models/student_loans_data_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ def found_data?
student_loans_data.any?
end

# This is used for the TSLR journey only
# The meaning of 'has_student_loan' seems to be different for this journey - it means has_student_loan_data
def has_student_loan_for_student_loan_policy
found_data?
end

def has_student_loan?
return unless found_data?

Expand All @@ -24,11 +18,6 @@ def student_loan_repayment_amount
student_loans_data.total_repayment_amount
end

# This is used for the TSLR journey only
def student_loan_plan_for_student_loan_policy
student_loans_data.repaying_plan_types || Claim::NO_STUDENT_LOAN
end

def student_loan_plan
return nil if student_loans_data.repaying_plan_types.nil? && !found_data?

Expand Down
6 changes: 6 additions & 0 deletions spec/factories/student_loans_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
no_of_plans_currently_repaying { 1 }
plan_type_of_deduction { 1 }
amount { 150 }

trait :no_student_loan do
no_of_plans_currently_repaying { nil }
plan_type_of_deduction { nil }
amount { 0 }
end
end
end
6 changes: 3 additions & 3 deletions spec/features/admin/upload_slc_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
expect(page).to have_content "No match"
end
expect(sl_claim_with_slc_data_no_student_loan.reload.student_loan_plan).to eq "not_applicable"
expect(sl_claim_with_slc_data_no_student_loan.has_student_loan).to be true # is this correct?
expect(sl_claim_with_slc_data_no_student_loan.has_student_loan).to be false
expect(sl_claim_with_slc_data_no_student_loan.eligibility.student_loan_repayment_amount).to eq 0

visit admin_claims_path
Expand All @@ -73,8 +73,8 @@
within "li.student_loan_amount" do
expect(page).to have_content "No data"
end
expect(sl_claim_no_slc_data.reload.student_loan_plan).to eq "not_applicable"
expect(sl_claim_no_slc_data.has_student_loan).to be false
expect(sl_claim_no_slc_data.reload.student_loan_plan).to be nil
expect(sl_claim_no_slc_data.has_student_loan).to be nil
expect(sl_claim_no_slc_data.eligibility.student_loan_repayment_amount).to eq 0

# Early Career Payments
Expand Down
2 changes: 1 addition & 1 deletion spec/features/student_loans_claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def fill_in_remaining_personal_details_and_submit

expect(answers).not_to have_student_loan
expect(answers.student_loan_repayment_amount).to eql(0)
expect(answers.student_loan_plan).to eql(Claim::NO_STUDENT_LOAN)
expect(answers.student_loan_plan).to be nil

fill_in_remaining_personal_details_and_submit
end
Expand Down
8 changes: 3 additions & 5 deletions spec/models/claim_student_loan_details_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
context "when the policy is StudentLoans" do
let(:policy) { Policies::StudentLoans }

it "updates the claim with no student plan and zero repayment total" do
expect { call }.to change { claim.reload.has_student_loan }.to(false)
.and change { claim.student_loan_plan }.to(Claim::NO_STUDENT_LOAN)
.and change { claim.eligibility.student_loan_repayment_amount }.to(0)
it "does not update the claim student plan and zero repayment total" do
expect { call }.not_to change { claim.reload.has_student_loan }
end

it "keeps the `submitted_using_slc_data` flag to `false` (default)" do
Expand Down Expand Up @@ -92,7 +90,7 @@

context "when the policy is StudentLoans" do
it "updates the claim with the student plan and the repayment total" do
expect { call }.to change { claim.reload.has_student_loan }.to(true)
expect { call }.to change { claim.reload.has_student_loan }.to(false)
.and change { claim.student_loan_plan }.to(Claim::NO_STUDENT_LOAN)
.and change { claim.eligibility.student_loan_repayment_amount }.to(0)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/student_loans/eligibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
context "when the has_student_loan claim flag is false" do
let(:claim) { build(:claim, has_student_loan: false) }

it { is_expected.not_to be_ineligible } # why are they eligible if they don't have a student loan?
it { is_expected.to be_ineligible }
end

context "when the has_student_loan claim flag is nil" do
Expand Down
53 changes: 44 additions & 9 deletions spec/requests/claims_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,28 @@ def check_slug_redirection
set_slug_sequence_in_session(journey_session, "personal-details")
end

it "updates the student loan details" do
expect { request }.to change { journey_session.reload.answers.has_student_loan }
.and change { journey_session.reload.answers.student_loan_plan }
context "when there is no student loan data for the claimant" do
it "does not update the student loan details" do
expect { request }.not_to change { journey_session.reload }
end
end

context "when there is student loan data showing the claimant has a student loan" do
before { create(:student_loans_data, nino: "QQ123456C", date_of_birth: Date.new(1990, 1, 1)) }

it "updates the student loan details" do
expect { request }.to change { journey_session.reload.answers.has_student_loan }.to(true)
.and change { journey_session.reload.answers.student_loan_plan }.to("plan_1")
end
end

context "when there is student loan data showing the claimant does not have student loan" do
before { create(:student_loans_data, :no_student_loan, nino: "QQ123456C", date_of_birth: Date.new(1990, 1, 1)) }

it "updates the student loan details" do
expect { request }.to change { journey_session.reload.answers.has_student_loan }.to(false)
.and change { journey_session.reload.answers.student_loan_plan }.to("not_applicable")
end
end
end

Expand Down Expand Up @@ -248,12 +267,28 @@ def check_slug_redirection
journey_session.save!
end

it "updates the student loan details" do
expect { request }.to(
change { journey_session.reload.answers.has_student_loan }.and(
change { journey_session.reload.answers.student_loan_plan }
)
)
context "when there is no student loan data for the claimant" do
it "does not update the student loan details" do
expect { request }.not_to change { journey_session.reload }
end
end

context "when there is student loan data showing the claimant has a student loan" do
before { create(:student_loans_data, nino: "QQ123456C", date_of_birth: Date.new(1990, 1, 1)) }

it "updates the student loan details" do
expect { request }.to change { journey_session.reload.answers.has_student_loan }.to(true)
.and change { journey_session.reload.answers.student_loan_plan }.to("plan_1")
end
end

context "when there is student loan data showing the claimant does not have student loan" do
before { create(:student_loans_data, :no_student_loan, nino: "QQ123456C", date_of_birth: Date.new(1990, 1, 1)) }

it "updates the student loan details" do
expect { request }.to change { journey_session.reload.answers.has_student_loan }.to(false)
.and change { journey_session.reload.answers.student_loan_plan }.to("not_applicable")
end
end
end

Expand Down

0 comments on commit afc065e

Please sign in to comment.