diff --git a/app/models/claim_student_loan_details_updater.rb b/app/models/claim_student_loan_details_updater.rb index d71f382739..254d779ed7 100644 --- a/app/models/claim_student_loan_details_updater.rb +++ b/app/models/claim_student_loan_details_updater.rb @@ -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 @@ -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, diff --git a/app/models/journeys/teacher_student_loan_reimbursement/answers_student_loans_details_updater.rb b/app/models/journeys/teacher_student_loan_reimbursement/answers_student_loans_details_updater.rb index 30cff8075c..85a18fb829 100644 --- a/app/models/journeys/teacher_student_loan_reimbursement/answers_student_loans_details_updater.rb +++ b/app/models/journeys/teacher_student_loan_reimbursement/answers_student_loans_details_updater.rb @@ -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 diff --git a/app/models/policies/student_loans/policy_eligibility_checker.rb b/app/models/policies/student_loans/policy_eligibility_checker.rb index e5a086300d..17ba4165e4 100644 --- a/app/models/policies/student_loans/policy_eligibility_checker.rb +++ b/app/models/policies/student_loans/policy_eligibility_checker.rb @@ -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 diff --git a/app/models/student_loans_data_presenter.rb b/app/models/student_loans_data_presenter.rb index 33d9300a22..cb9ca2ffd8 100644 --- a/app/models/student_loans_data_presenter.rb +++ b/app/models/student_loans_data_presenter.rb @@ -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? @@ -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? diff --git a/spec/factories/student_loans_data.rb b/spec/factories/student_loans_data.rb index 1c2d14f421..bd30a0e550 100644 --- a/spec/factories/student_loans_data.rb +++ b/spec/factories/student_loans_data.rb @@ -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 diff --git a/spec/features/admin/upload_slc_data_spec.rb b/spec/features/admin/upload_slc_data_spec.rb index cad4af05dc..be6ba41464 100644 --- a/spec/features/admin/upload_slc_data_spec.rb +++ b/spec/features/admin/upload_slc_data_spec.rb @@ -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 @@ -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 diff --git a/spec/features/student_loans_claim_spec.rb b/spec/features/student_loans_claim_spec.rb index 47428cce5a..ed306fef27 100644 --- a/spec/features/student_loans_claim_spec.rb +++ b/spec/features/student_loans_claim_spec.rb @@ -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 diff --git a/spec/models/claim_student_loan_details_updater_spec.rb b/spec/models/claim_student_loan_details_updater_spec.rb index 558f3906ef..450c270eec 100644 --- a/spec/models/claim_student_loan_details_updater_spec.rb +++ b/spec/models/claim_student_loan_details_updater_spec.rb @@ -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 @@ -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 diff --git a/spec/models/student_loans/eligibility_spec.rb b/spec/models/student_loans/eligibility_spec.rb index 77977b2147..6530b71ca4 100644 --- a/spec/models/student_loans/eligibility_spec.rb +++ b/spec/models/student_loans/eligibility_spec.rb @@ -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 diff --git a/spec/requests/claims_spec.rb b/spec/requests/claims_spec.rb index 4cd547c865..68f255aca7 100644 --- a/spec/requests/claims_spec.rb +++ b/spec/requests/claims_spec.rb @@ -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 @@ -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