diff --git a/app/controllers/providers/capital_income_assessment_results_controller.rb b/app/controllers/providers/capital_income_assessment_results_controller.rb index 5da3445c4ee..f1b702eb7e2 100644 --- a/app/controllers/providers/capital_income_assessment_results_controller.rb +++ b/app/controllers/providers/capital_income_assessment_results_controller.rb @@ -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 @@ -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 = ":

" - ineligible_reasons_array.each { |reason| ineligible_reasons += "-#{reason}
" } - 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 diff --git a/app/helpers/ineligible_reasons_helper.rb b/app/helpers/ineligible_reasons_helper.rb new file mode 100644 index 00000000000..95c4a3d5a29 --- /dev/null +++ b/app/helpers/ineligible_reasons_helper.rb @@ -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 = ":" + 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 diff --git a/app/views/shared/assessment_results/_ineligible.html.erb b/app/views/shared/assessment_results/_ineligible.html.erb index 458c36c7eed..a407bbcb9d2 100644 --- a/app/views/shared/assessment_results/_ineligible.html.erb +++ b/app/views/shared/assessment_results/_ineligible.html.erb @@ -4,6 +4,6 @@
-

<%= sanitize(t(".detail", ineligible_reasons: @ineligible_reasons)) %>

+

<%= sanitize(t(".detail", ineligible_reasons: ineligible_reasons(@cfe_result))) %>

diff --git a/spec/factories/cfe_results/v6/mock_results.rb b/spec/factories/cfe_results/v6/mock_results.rb index 37d9345292c..63009ddf7bb 100644 --- a/spec/factories/cfe_results/v6/mock_results.rb +++ b/spec/factories/cfe_results/v6/mock_results.rb @@ -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 diff --git a/spec/factories/cfe_results/v6/results.rb b/spec/factories/cfe_results/v6/results.rb index 4261fee523a..b0c00e786bf 100644 --- a/spec/factories/cfe_results/v6/results.rb +++ b/spec/factories/cfe_results/v6/results.rb @@ -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 diff --git a/spec/helpers/ineligible_reasons_helper_spec.rb b/spec/helpers/ineligible_reasons_helper_spec.rb new file mode 100644 index 00000000000..24c7155e8fc --- /dev/null +++ b/spec/helpers/ineligible_reasons_helper_spec.rb @@ -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 ":" + end + end + end +end diff --git a/spec/requests/providers/capital_assessment_results_controller_spec.rb b/spec/requests/providers/capital_assessment_results_controller_spec.rb index 5de03ab5390..7f70ed043ef 100644 --- a/spec/requests/providers/capital_assessment_results_controller_spec.rb +++ b/spec/requests/providers/capital_assessment_results_controller_spec.rb @@ -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) @@ -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 @@ -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) } diff --git a/spec/requests/providers/capital_income_assessment_results_controller_spec.rb b/spec/requests/providers/capital_income_assessment_results_controller_spec.rb index 1170683df15..e250ecd16f3 100644 --- a/spec/requests/providers/capital_income_assessment_results_controller_spec.rb +++ b/spec/requests/providers/capital_income_assessment_results_controller_spec.rb @@ -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 @@ -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 @@ -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) }