Skip to content

Commit

Permalink
[LUPEYALPHA-1010] student loan plan task for FE (#3168)
Browse files Browse the repository at this point in the history
* Student Loan Plan job for FE
* refactor - use Policy#auto_check_student_loan_plan_task?
  • Loading branch information
alkesh authored Sep 23, 2024
1 parent e1067f2 commit 0390808
Show file tree
Hide file tree
Showing 23 changed files with 271 additions and 66 deletions.
6 changes: 5 additions & 1 deletion app/controllers/claims_form_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def on_tid_route?
end

def journey_requires_student_loan_details?
student_loans_journey? || additional_payments_journey? || get_a_teacher_relocation_payment_journey?
student_loans_journey? || additional_payments_journey? || get_a_teacher_relocation_payment_journey? || further_education_payments_journey?
end

def student_loans_journey?
Expand All @@ -139,4 +139,8 @@ def additional_payments_journey?
def get_a_teacher_relocation_payment_journey?
current_journey_routing_name == "get-a-teacher-relocation-payment"
end

def further_education_payments_journey?
current_journey_routing_name == "further-education-payments"
end
end
23 changes: 12 additions & 11 deletions app/jobs/student_loan_plan_check_job.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
class StudentLoanPlanCheckJob < ApplicationJob
APPLICABLE_POLICIES = [
Policies::EarlyCareerPayments,
Policies::LevellingUpPremiumPayments,
Policies::FurtherEducationPayments
].freeze

def perform
delete_no_data_student_loan_plan_tasks
claims = current_year_ecp_lup_claims_awaiting_decision.awaiting_task("student_loan_plan")

claims = current_year_claims_awaiting_decision.awaiting_task("student_loan_plan")
claims.each do |claim|
ClaimStudentLoanDetailsUpdater.call(claim)
AutomatedChecks::ClaimVerifiers::StudentLoanPlan.new(claim:).perform
Expand All @@ -12,22 +17,18 @@ def perform
private

def delete_no_data_student_loan_plan_tasks
claim_ids = current_year_ecp_lup_claims_with_no_data_tasks.pluck(:id)
claim_ids = current_year_claims_with_no_data_tasks.pluck(:id)

claim_ids.each_slice(500) do |ids|
Task.where(claim_id: ids, name: "student_loan_plan", claim_verifier_match: nil, manual: false).delete_all
end
end

def current_year_ecp_lup_claims_with_no_data_tasks
current_year_ecp_lup_claims_awaiting_decision.joins(:tasks).where(tasks: {name: "student_loan_plan", claim_verifier_match: nil, manual: false})
end

def current_year_ecp_lup_claims_awaiting_decision
Claim.by_academic_year(current_academic_year).by_policies([Policies::EarlyCareerPayments, Policies::LevellingUpPremiumPayments]).awaiting_decision.where(submitted_using_slc_data: false)
def current_year_claims_with_no_data_tasks
current_year_claims_awaiting_decision.joins(:tasks).where(tasks: {name: "student_loan_plan", claim_verifier_match: nil, manual: false})
end

def current_academic_year
Journeys.for_policy(Policies::EarlyCareerPayments).configuration.current_academic_year
def current_year_claims_awaiting_decision
Claim::ClaimsAwaitingDecisionFinder.new(policies: APPLICABLE_POLICIES).claims_submitted_without_slc_data
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(claim:, admin_user: nil)
end

def perform
return unless claim.has_ecp_or_lupp_policy?
return unless claim.policy.auto_check_student_loan_plan_task?
return unless claim.submitted_without_slc_data?
return unless awaiting_task?

Expand Down
4 changes: 4 additions & 0 deletions app/models/base_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ def international_relocation_payments?
def further_education_payments?
to_s == "FurtherEducationPayments"
end

def auto_check_student_loan_plan_task?
false
end
end
3 changes: 2 additions & 1 deletion app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ def must_manually_validate_bank_details?
end

def submitted_without_slc_data?
submitted_using_slc_data == false
# FE claims prior to the deployment of LUPEYALPHA-1010 have submitted_using_slc_data = nil
submitted_using_slc_data != true
end

def has_dqt_record?
Expand Down
31 changes: 31 additions & 0 deletions app/models/claim/claims_awaiting_decision_finder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Claim
class ClaimsAwaitingDecisionFinder
def initialize(policies:)
@policies = policies
end

attr_reader :policies

def claims_submitted_without_slc_data
policies.map do |policy|
journey_configuration = Journeys.for_policy(policy).configuration
Claim
.by_academic_year(journey_configuration.current_academic_year)
.by_policy(policy)
.awaiting_decision
.where(submitted_using_slc_data: submitted_using_slc_data(policy))
end.reduce(&:or)
end

private

def submitted_using_slc_data(policy)
if policy == Policies::FurtherEducationPayments
# For 2024/2025 academic year onwards, only FE claims prior to the deployment of LUPEYALPHA-1010 have submitted_using_slc_data = nil
[false, nil]
else
false
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Journeys
module FurtherEducationPayments
class AnswersStudentLoansDetailsUpdater < Journeys::AnswersStudentLoansDetailsUpdater
end
end
end
4 changes: 4 additions & 0 deletions app/models/policies/early_career_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,9 @@ def student_loan_balance_url
def payment_and_deductions_info_url
eligibility_page_url + "#paying-income-tax-and-national-insurance"
end

def auto_check_student_loan_plan_task?
true
end
end
end
4 changes: 4 additions & 0 deletions app/models/policies/further_education_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,9 @@ def verification_due_date_for_claim(claim)
def duplicate_claim?(claim)
Claim::MatchingAttributeFinder.new(claim).matching_claims.exists?
end

def auto_check_student_loan_plan_task?
true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def applicable_task_names
tasks << "identity_confirmation"
tasks << "provider_verification"
tasks << "employment" if claim.eligibility.teacher_reference_number.present?
tasks << "student_loan_plan"
tasks << "student_loan_plan" if claim.submitted_without_slc_data?
tasks << "payroll_details" if claim.must_manually_validate_bank_details?
tasks << "matching_details" if matching_claims.exists?
tasks << "payroll_gender" if claim.payroll_gender_missing?
Expand Down
4 changes: 4 additions & 0 deletions app/models/policies/levelling_up_premium_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ def payment_and_deductions_info_url
def payroll_file_name
"SchoolsLUP"
end

def auto_check_student_loan_plan_task?
true
end
end
end
2 changes: 2 additions & 0 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
claim_academic_year =
if [Policies::EarlyCareerPayments, Policies::LevellingUpPremiumPayments].include?(evaluator.policy)
Journeys::AdditionalPaymentsForTeaching.configuration.current_academic_year
elsif evaluator.policy == Policies::FurtherEducationPayments
Journeys::FurtherEducationPayments.configuration.current_academic_year
else
AcademicYear::Type.new.serialize(AcademicYear.new(2019))
end
Expand Down
152 changes: 110 additions & 42 deletions spec/features/admin/upload_slc_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
before do
create(:journey_configuration, :student_loans) # used by StudentLoanAmountCheckJob
create(:journey_configuration, :early_career_payments)
create(:journey_configuration, :further_education_payments)
sign_in_as_service_operator
end

Expand Down Expand Up @@ -39,6 +40,37 @@
has_student_loan: false, student_loan_plan: "not_applicable", submitted_using_slc_data: false)
}

let!(:fe_claim_with_slc_data_no_student_loan_nil_submitted_using_slc_data) {
create(:claim, :submitted, policy: Policies::FurtherEducationPayments,
eligibility: build(:further_education_payments_eligibility, :eligible),
has_student_loan: nil, student_loan_plan: nil, submitted_using_slc_data: nil) # having nil submitted_using_slc_data won't happen after LUPEYALPHA-1010 merged
}
let!(:fe_claim_with_slc_data_with_student_loan_nil_submitted_using_slc_data) {
create(:claim, :submitted, policy: Policies::FurtherEducationPayments,
eligibility: build(:further_education_payments_eligibility, :eligible),
has_student_loan: nil, student_loan_plan: nil, submitted_using_slc_data: nil) # having nil submitted_using_slc_data won't happen after LUPEYALPHA-1010 merged
}
let!(:fe_claim_no_slc_data_nil_submitted_using_slc_data) {
create(:claim, :submitted, :with_student_loan, policy: Policies::FurtherEducationPayments,
eligibility: build(:further_education_payments_eligibility, :eligible),
has_student_loan: nil, student_loan_plan: nil, submitted_using_slc_data: nil) # having nil submitted_using_slc_data won't happen after LUPEYALPHA-1010 merged
}
let!(:fe_claim_with_slc_data_no_student_loan) {
create(:claim, :submitted, policy: Policies::FurtherEducationPayments,
eligibility: build(:further_education_payments_eligibility, :eligible),
has_student_loan: nil, student_loan_plan: nil, submitted_using_slc_data: false)
}
let!(:fe_claim_with_slc_data_with_student_loan) {
create(:claim, :submitted, policy: Policies::FurtherEducationPayments,
eligibility: build(:further_education_payments_eligibility, :eligible),
has_student_loan: nil, student_loan_plan: nil, submitted_using_slc_data: false)
}
let!(:fe_claim_no_slc_data) {
create(:claim, :submitted, :with_student_loan, policy: Policies::FurtherEducationPayments,
eligibility: build(:further_education_payments_eligibility, :eligible),
has_student_loan: nil, student_loan_plan: nil, submitted_using_slc_data: false)
}

scenario "automated task to verify student loan plan" do
visit admin_claims_path
click_link "Upload SLC data"
Expand All @@ -47,64 +79,96 @@
click_button "Upload"
end
expect(page).to have_content "SLC file uploaded and queued to be imported"
expect(StudentLoansData.count).to eq 4
expect(StudentLoansData.count).to eq 8

# Student Loans

click_link sl_claim_with_slc_data_no_student_loan.reference
expect(page).to have_content "Student loan amount"
within "li.student_loan_amount" do
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 false
expect(sl_claim_with_slc_data_no_student_loan.eligibility.student_loan_repayment_amount).to eq 0

visit admin_claims_path
click_link ecp_claim_with_slc_data_with_student_loan.reference
expect(page).not_to have_content "Student loan amount"
expect(sl_claim_with_slc_data_with_student_loan.reload.student_loan_plan).to eq "plan_1"
expect(sl_claim_with_slc_data_with_student_loan.has_student_loan).to eq true
expect(sl_claim_with_slc_data_with_student_loan.eligibility.student_loan_repayment_amount).to eq 100
claim = sl_claim_with_slc_data_no_student_loan
then_the_student_loan_amount_task_should_show_as(state: "No match", for_claim: claim)
expect(claim.reload.student_loan_plan).to eq "not_applicable"
expect(claim.has_student_loan).to be false
expect(claim.eligibility.student_loan_repayment_amount).to eq 0

claim = sl_claim_with_slc_data_with_student_loan
visit admin_claims_path
click_link sl_claim_no_slc_data.reference
expect(page).to have_content "Student loan amount"
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 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
click_link claim.reference
then_the_student_loan_amount_task_should_show_as(state: "Passed", for_claim: claim)
expect(claim.reload.student_loan_plan).to eq "plan_1"
expect(claim.has_student_loan).to eq true
expect(claim.eligibility.student_loan_repayment_amount).to eq 100

claim = sl_claim_no_slc_data
then_the_student_loan_amount_task_should_show_as(state: "No data", for_claim: claim)
expect(claim.reload.student_loan_plan).to be nil
expect(claim.has_student_loan).to be nil
expect(claim.eligibility.student_loan_repayment_amount).to eq 0

# Early Career Payments

visit admin_claims_path
click_link ecp_claim_with_slc_data_no_student_loan.reference
expect(page).to have_content "Student loan plan"
within "li.student_loan_plan" do
expect(page).to have_content "Passed"
end
expect(ecp_claim_with_slc_data_no_student_loan.reload.student_loan_plan).to eq "not_applicable"
expect(ecp_claim_with_slc_data_no_student_loan.has_student_loan).to be false
claim = ecp_claim_with_slc_data_no_student_loan
then_the_student_loan_plan_task_should_show_as(state: "Passed", for_claim: claim)
expect(claim.reload.student_loan_plan).to eq "not_applicable"
expect(claim.has_student_loan).to be false

claim = ecp_claim_with_slc_data_with_student_loan
then_the_student_loan_plan_task_should_show_as(state: "Passed", for_claim: claim)
expect(claim.reload.student_loan_plan).to eq "plan_1"
expect(claim.has_student_loan).to eq true

claim = ecp_claim_no_slc_data
then_the_student_loan_plan_task_should_show_as(state: "No data", for_claim: claim)
expect(claim.reload.student_loan_plan).to be nil # this was "not_applicable" before LUPEYALPHA-1031
expect(claim.has_student_loan).to be nil # this was false before LUPEYALPHA-1031

# Further Education Payments

claim = fe_claim_with_slc_data_no_student_loan_nil_submitted_using_slc_data
then_the_student_loan_plan_task_should_show_as(state: "Passed", for_claim: claim)
expect(claim.reload.student_loan_plan).to eq "not_applicable"
expect(claim.has_student_loan).to eq false

claim = fe_claim_with_slc_data_with_student_loan_nil_submitted_using_slc_data
then_the_student_loan_plan_task_should_show_as(state: "Passed", for_claim: claim)
expect(claim.reload.student_loan_plan).to eq "plan_1"
expect(claim.has_student_loan).to eq true

claim = fe_claim_no_slc_data_nil_submitted_using_slc_data
then_the_student_loan_plan_task_should_show_as(state: "No data", for_claim: claim)
expect(claim.reload.student_loan_plan).to be nil
expect(claim.has_student_loan).to be nil

claim = fe_claim_with_slc_data_no_student_loan
then_the_student_loan_plan_task_should_show_as(state: "Passed", for_claim: claim)
expect(claim.reload.student_loan_plan).to eq "not_applicable"
expect(claim.has_student_loan).to eq false

claim = fe_claim_with_slc_data_with_student_loan
then_the_student_loan_plan_task_should_show_as(state: "Passed", for_claim: claim)
expect(claim.reload.student_loan_plan).to eq "plan_1"
expect(claim.has_student_loan).to eq true

claim = fe_claim_no_slc_data
then_the_student_loan_plan_task_should_show_as(state: "No data", for_claim: claim)
expect(claim.reload.student_loan_plan).to be nil
expect(claim.has_student_loan).to be nil
end

def then_the_student_loan_amount_task_should_show_as(state:, for_claim:)
visit admin_claims_path
click_link ecp_claim_with_slc_data_with_student_loan.reference
expect(page).to have_content "Student loan plan"
within "li.student_loan_plan" do
expect(page).to have_content "Passed"
click_link for_claim.reference
expect(page).to have_content "Student loan amount"
within "li.student_loan_amount" do
expect(page).to have_content state
end
expect(ecp_claim_with_slc_data_with_student_loan.reload.student_loan_plan).to eq "plan_1"
expect(ecp_claim_with_slc_data_with_student_loan.has_student_loan).to eq true
end

def then_the_student_loan_plan_task_should_show_as(state:, for_claim:)
visit admin_claims_path
click_link ecp_claim_no_slc_data.reference
click_link for_claim.reference
expect(page).to have_content "Student loan plan"
within "li.student_loan_plan" do
expect(page).to have_content "No data"
expect(page).to have_content state
end
expect(ecp_claim_no_slc_data.reload.student_loan_plan).to be nil # this was "not_applicable" before LUPEYALPHA-1031
expect(ecp_claim_no_slc_data.has_student_loan).to be nil # this was false before LUPEYALPHA-1031
end

def slc_data_csv_file
Expand All @@ -116,6 +180,10 @@ def slc_data_csv_file
@slc_data_csv_file.write csv_row(sl_claim_with_slc_data_with_student_loan, plan_type: "1", amount: "100")
@slc_data_csv_file.write csv_row(ecp_claim_with_slc_data_no_student_loan, no_data: true)
@slc_data_csv_file.write csv_row(ecp_claim_with_slc_data_with_student_loan, plan_type: "1", amount: "100")
@slc_data_csv_file.write csv_row(fe_claim_with_slc_data_no_student_loan, no_data: true)
@slc_data_csv_file.write csv_row(fe_claim_with_slc_data_with_student_loan, plan_type: "1", amount: "100")
@slc_data_csv_file.write csv_row(fe_claim_with_slc_data_no_student_loan_nil_submitted_using_slc_data, no_data: true)
@slc_data_csv_file.write csv_row(fe_claim_with_slc_data_with_student_loan_nil_submitted_using_slc_data, plan_type: "1", amount: "100")

@slc_data_csv_file.rewind

Expand Down
2 changes: 2 additions & 0 deletions spec/features/further_education_payments/happy_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let(:expected_award_amount) { college.eligible_fe_provider.max_award_amount }

scenario "happy path claim" do
when_student_loan_data_exists
when_further_education_payments_journey_configuration_exists
and_college_exists

Expand Down Expand Up @@ -183,6 +184,7 @@

expect(claim.first_name).to eql("John")
expect(claim.surname).to eql("Doe")
expect(claim.student_loan_plan).to eq "plan_1"

eligibility = Policies::FurtherEducationPayments::Eligibility.last

Expand Down
Loading

0 comments on commit 0390808

Please sign in to comment.