Skip to content

Commit

Permalink
ap-4503: Add ineligible_reasons_helper to help with display of inelig…
Browse files Browse the repository at this point in the history
…ible reasons
  • Loading branch information
kmahern committed Nov 14, 2023
1 parent 1281376 commit 7bd3889
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def show
handle_unknown
@details = ManualReviewDetailer.call(legal_aid_application)
@result_partial = ResultsPanelSelector.call(legal_aid_application)
@ineligible_reasons = ineligible_reasons if @cfe_result.assessment_result == "ineligible"
end

def update
Expand All @@ -21,45 +20,5 @@ def handle_unknown

raise "Unknown capital_income_assessment_result: '#{@cfe_result.assessment_result}'"
end

def ineligible_reasons
return "" unless @cfe_result.assessment_result == "ineligible"
return ineligible_reasons_array.first if ineligible_reasons_array.length == 1

ineligible_reasons = ":<br><br>"
ineligible_reasons_array.each { |reason| ineligible_reasons += "-#{reason}<br>" }
ineligible_reasons
end

def ineligible_reasons_array
return [] unless @cfe_result.assessment_result == "ineligible"

ineligible_reasons_array = []
ineligible_reasons_array << "gross income" if ineligible_gross_income?
ineligible_reasons_array << "disposable income" if ineligible_disposable_income?
ineligible_reasons_array << "disposable capital" if ineligible_disposable_capital?
ineligible_reasons_array
end

def ineligible_gross_income?
return false unless @cfe_result.assessment_result == "ineligible"
return false unless (@cfe_result.gross_income_results - %w[ineligible]).empty?

true
end

def ineligible_disposable_income?
return false unless @cfe_result.assessment_result == "ineligible"
return false unless (@cfe_result.disposable_income_results - %w[ineligible]).empty?

true
end

def ineligible_disposable_capital?
return false unless @cfe_result.assessment_result == "ineligible"
return false unless (@cfe_result.capital_results - %w[ineligible]).empty?

true
end
end
end
40 changes: 40 additions & 0 deletions app/helpers/ineligible_reasons_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module IneligibleReasonsHelper
def ineligible_reasons(cfe_result)
return "" unless cfe_result.assessment_result == "ineligible"

reasons = ineligible_reasons_array(cfe_result)
return reasons.first if reasons.length == 1

ineligible_reasons = ":<ul class='govuk-list govuk-list--bullet'>"
reasons.each { |reason| ineligible_reasons += "<li>#{reason}</li>" }
ineligible_reasons += "</ul>"
end

private

def ineligible_reasons_array(cfe_result)
ineligible_reasons_array = []
ineligible_reasons_array << "gross income" if ineligible_gross_income?(cfe_result)
ineligible_reasons_array << "disposable income" if ineligible_disposable_income?(cfe_result)
ineligible_reasons_array << "disposable capital" if ineligible_disposable_capital?(cfe_result)
ineligible_reasons_array
end

def ineligible_gross_income?(cfe_result)
return false unless (cfe_result.gross_income_results - %w[ineligible]).empty?

true
end

def ineligible_disposable_income?(cfe_result)
return false unless (cfe_result.disposable_income_results - %w[ineligible]).empty?

true
end

def ineligible_disposable_capital?(cfe_result)
return false unless (cfe_result.capital_results - %w[ineligible]).empty?

true
end
end
2 changes: 1 addition & 1 deletion app/views/shared/assessment_results/_ineligible.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<p class="govuk-body"><%= sanitize(t(".detail", ineligible_reasons: @ineligible_reasons)) %></p>
<p class="govuk-body"><%= sanitize(t(".detail", ineligible_reasons: ineligible_reasons(@cfe_result))) %></p>
</div>
</div>
93 changes: 93 additions & 0 deletions spec/factories/cfe_results/v6/mock_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,99 @@ def self.ineligible_disposable_income
}
result
end

# This result has has been faked, to cover an example where CFE returns 'ineligible'
# for more than one proceeding category, which it appears is currently not possible.
# Currently if an applicant is ineligible for disposable income and capital,
# CFE returns the disposable income result for proceedings as 'ineligible',
# but the capital result for proceedings as 'pending'.
# Have added this mock result as there is code to cover the scenario where CFE returns
# an ineligible result for more than one category e.g. disposable income and capital
# even though it appears this is not currently not happening.
# Is this required?
def self.fake_ineligible_disposable_income_and_capital
result = eligible
result[:result_summary][:overall_result][:result] = "ineligible"
result[:result_summary][:gross_income] = {
total_gross_income: 1000.0,
proceeding_types: [{ ccms_code: "SE100E",
upper_threshold: 2657.0,
lower_threshold: 0.0,
result: "eligible",
client_involvement_type: "A" },
{ ccms_code: "SE101E",
upper_threshold: 2657.0,
lower_threshold: 0.0,
result: "eligible",
client_involvement_type: "A" }],
combined_total_gross_income: 1000.0,
}
result[:result_summary][:disposable_income] = {
dependant_allowance_under_16: 0,
dependant_allowance_over_16: 0,
dependant_allowance: 0,
gross_housing_costs: 0.0,
housing_benefit: 0.0,
net_housing_costs: 0.0,
maintenance_allowance: 0.0,
total_outgoings_and_allowances: 0.0,
total_disposable_income: 1000.0,
employment_income: { gross_income: 0.0,
benefits_in_kind: 0.0,
tax: 0.0,
national_insurance: 0.0,
prisoner_levy: 0.0,
student_debt_repayment: 0.0,
fixed_employment_deduction: 0.0,
net_employment_income: 0.0 },
proceeding_types: [{ ccms_code: "SE100E",
upper_threshold: 733.0,
lower_threshold: 315.0,
result: "ineligible",
client_involvement_type: "A" },
{ ccms_code: "SE101E",
upper_threshold: 733.0,
lower_threshold: 315.0,
result: "ineligible",
client_involvement_type: "A" }],
combined_total_disposable_income: 1000.0,
combined_total_outgoings_and_allowances: 0.0,
partner_allowance: 0,
lone_parent_allowance: 0,
income_contribution: 0.0,
}
result[:result_summary][:capital] = {
pensioner_disregard_applied: 0.0,
total_liquid: 500_000.0,
total_non_liquid: 0.0,
total_vehicle: 0.0,
total_property: 0.0,
total_mortgage_allowance: 999_999_999_999.0,
total_capital: 500_000.0,
subject_matter_of_dispute_disregard: 0.0,
assessed_capital: 500_000.0,
total_capital_with_smod: 500_000.0,
disputed_non_property_disregard: 0,
proceeding_types: [
{ ccms_code: "SE097A",
upper_threshold: 8000.0,
lower_threshold: 3000.0,
result: "ineligible",
client_involvement_type: "A" },
{ ccms_code: "SE101E",
upper_threshold: 8000.0,
lower_threshold: 3000.0,
result: "ineligible",
client_involvement_type: "A" },
],
combined_disputed_capital: 0,
combined_non_disputed_capital: 500_000.0,
capital_contribution: 497_000.0,
pensioner_capital_disregard: 0.0,
combined_assessed_capital: 500_000.0,
}
result
end
end
end
end
4 changes: 4 additions & 0 deletions spec/factories/cfe_results/v6/results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module V6
trait :ineligible_capital do
result { CFEResults::V6::MockResults.ineligible_capital.to_json }
end

trait :fake_ineligible_disposable_income_and_capital do
result { CFEResults::V6::MockResults.fake_ineligible_disposable_income_and_capital.to_json }
end
end
end
end
Expand Down
53 changes: 53 additions & 0 deletions spec/helpers/ineligible_reasons_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require "rails_helper"

RSpec.describe IneligibleReasonsHelper do
let(:eligible_result) { create(:cfe_v6_result) }
let(:ineligible_gross_income_result) { create(:cfe_v6_result, :ineligible_gross_income) }
let(:ineligible_disposable_income_result) { create(:cfe_v6_result, :ineligible_disposable_income) }
let(:ineligible_capital_result) { create(:cfe_v6_result, :ineligible_capital) }
let(:ineligible_disposable_income_and_capital_result) { create(:cfe_v6_result, :fake_ineligible_disposable_income_and_capital) }

describe ".ineligible_reasons" do
subject(:reasons) { ineligible_reasons(cfe_result) }

context "when overall cfe result is eligible" do
let(:cfe_result) { eligible_result }

it "returns an empty string" do
expect(reasons).to eq ""
end
end

context "when overall cfe result is ineligible and applicant's gross income is above upper threshold" do
let(:cfe_result) { ineligible_gross_income_result }

it "returns 'gross income'" do
expect(reasons).to eq "gross income"
end
end

context "when overall cfe result is ineligible and applicant's disposable income is above upper threshold" do
let(:cfe_result) { ineligible_disposable_income_result }

it "returns 'disposable income'" do
expect(reasons).to eq "disposable income"
end
end

context "when overall cfe result is ineligible and applicant's capital is above upper threshold" do
let(:cfe_result) { ineligible_capital_result }

it "returns 'disposable capital'" do
expect(reasons).to eq "disposable capital"
end
end

context "when cfe returns ineligible for multiple categories; disposable income and capital" do
let(:cfe_result) { ineligible_disposable_income_and_capital_result }

it "returns a bulleted list of disposable income and capital" do
expect(reasons).to eq ":<ul class='govuk-list govuk-list--bullet'><li>disposable income</li><li>disposable capital</li></ul>"
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
end
end

context "when not eligible" do
let(:cfe_result) { create(:cfe_v3_result, :not_eligible) }
context "when ineligible and disposable capital is above the upper threshold" do
let(:cfe_result) { create(:cfe_v6_result, :ineligible_capital) }

it "returns http success" do
expect(response).to have_http_status(:ok)
Expand All @@ -46,6 +46,10 @@
it "displays the correct result" do
expect(unescaped_response_body).to include(I18n.t("ineligible.heading", name: applicant_name, scope: locale_scope))
end

it "displays the correct reason" do
expect(unescaped_response_body).to include("This is because they have too much disposable capital")
end
end

context "when capital contribution required" do
Expand Down Expand Up @@ -74,18 +78,6 @@
end
end

context "when not eligible" do
let(:cfe_result) { create(:cfe_v3_result, :not_eligible) }

it "returns http success" do
expect(response).to have_http_status(:ok)
end

it "displays the correct result" do
expect(unescaped_response_body).to include(I18n.t("ineligible.heading", name: applicant_name, scope: locale_scope))
end
end

context "when capital contribution required" do
let(:cfe_result) { create(:cfe_v3_result, :with_capital_contribution_required) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
end

context "when not eligible" do
context "when gross income is above the upper threshold" do
context "when ineligible and gross income is above the upper threshold" do
let(:cfe_result) { create(:cfe_v6_result, :ineligible_gross_income) }

it "returns http success" do
Expand All @@ -54,7 +54,7 @@
end
end

context "when disposable income is above the upper threshold" do
context "when ineligible and disposable income is above the upper threshold" do
let(:cfe_result) { create(:cfe_v6_result, :ineligible_disposable_income) }

it "returns http success" do
Expand All @@ -71,22 +71,6 @@
end
end

context "when disposable capital is above the upper threshold" do
let(:cfe_result) { create(:cfe_v6_result, :ineligible_capital) }

it "returns http success" do
expect(response).to have_http_status(:ok)
end

it "displays the correct result" do
expect(unescaped_response_body).to include(I18n.t("ineligible.heading", name: applicant_name, scope: locale_scope))
end

it "displays the correct reason" do
expect(unescaped_response_body).to include("This is because they have too much disposable capital")
end
end

context "when capital contribution required" do
let(:cfe_result) { create(:cfe_v4_result, :with_capital_contribution_required) }

Expand Down

0 comments on commit 7bd3889

Please sign in to comment.