Skip to content

Commit

Permalink
Set student loan plan for claim when it exists in student loan data f…
Browse files Browse the repository at this point in the history
…or FE
  • Loading branch information
alkesh committed Sep 23, 2024
1 parent e870669 commit 982a623
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 95 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
22 changes: 12 additions & 10 deletions app/jobs/student_loan_plan_check_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +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_fe_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 @@ -11,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_fe_claims_awaiting_decision.joins(:tasks).where(tasks: {name: "student_loan_plan", claim_verifier_match: nil, manual: false})
end

def current_year_ecp_lup_fe_claims_awaiting_decision
Claim.by_academic_year(current_academic_year).by_policies([Policies::EarlyCareerPayments, Policies::LevellingUpPremiumPayments, Policies::FurtherEducationPayments]).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
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
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
184 changes: 106 additions & 78 deletions spec/features/admin/upload_slc_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,36 @@
eligibility: build(:early_career_payments_eligibility, :eligible),
has_student_loan: false, student_loan_plan: "not_applicable", submitted_using_slc_data: false)
}
let!(:fe_claim_no_student_loan_plan_no_slc_data) {
create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility: build(:further_education_payments_eligibility, :eligible), has_student_loan: nil, student_loan_plan: nil)

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_student_loan_plan_in_slc_data) {
create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility: build(:further_education_payments_eligibility, :eligible), has_student_loan: nil, student_loan_plan: nil)
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_not_in_data_file) {
create(:claim, :submitted, :with_student_loan, policy: Policies::FurtherEducationPayments, eligibility: build(:further_education_payments_eligibility, :eligible))
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
Expand All @@ -57,94 +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

# FE

visit admin_claims_path
click_link fe_claim_no_student_loan_plan_no_slc_data.reference
within "li.student_loan_plan" do
expect(page).to have_content "Failed" # is this right?
end
expect(fe_claim_no_student_loan_plan_no_slc_data.reload.student_loan_plan).to eq "not_applicable"
expect(fe_claim_no_student_loan_plan_no_slc_data.has_student_loan).to eq true # doesn't seem right - legacy attribute
expect(fe_claim_no_student_loan_plan_no_slc_data.submitted_using_slc_data).to be false

visit admin_claims_path
click_link fe_claim_no_student_loan_plan_in_slc_data.reference
within "li.student_loan_plan" do
expect(page).to have_content "Passed"
end
expect(fe_claim_no_student_loan_plan_in_slc_data.reload.student_loan_plan).to eq "plan_1"
expect(fe_claim_no_student_loan_plan_in_slc_data.has_student_loan).to eq true
expect(fe_claim_no_student_loan_plan_in_slc_data.submitted_using_slc_data).to be false

visit admin_claims_path
click_link fe_claim_not_in_data_file.reference
within "li.student_loan_plan" do
expect(page).to have_content "No data"
end
expect(fe_claim_not_in_data_file.reload.student_loan_plan).to eq "not_applicable"
expect(fe_claim_not_in_data_file.has_student_loan).to eq false
expect(fe_claim_not_in_data_file.submitted_using_slc_data).to be false

end

def slc_data_csv_file
Expand All @@ -156,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 982a623

Please sign in to comment.