diff --git a/app/helpers/ineligible_reasons_helper.rb b/app/helpers/ineligible_reasons_helper.rb new file mode 100644 index 0000000000..ce868e9f34 --- /dev/null +++ b/app/helpers/ineligible_reasons_helper.rb @@ -0,0 +1,28 @@ +module IneligibleReasonsHelper + def ineligible_reasons(cfe_result) + return "" unless cfe_result.assessment_result == "ineligible" + + reasons = ineligible_reasons_array(cfe_result) + return ineligible_reason(reasons.first) if reasons.length == 1 + + ineligible_reasons = ":" + end + +private + + def ineligible_reason(reason) + t("shared.ineligible_reasons.#{reason}") + end + + def ineligible_reasons_array(cfe_result) + ineligible_reasons_array = [] + ineligible_reasons_array << "gross_income" if cfe_result.ineligible_gross_income? + ineligible_reasons_array << "disposable_income" if cfe_result.ineligible_disposable_income? + ineligible_reasons_array << "disposable_capital" if cfe_result.ineligible_disposable_capital? + ineligible_reasons_array + end +end diff --git a/app/models/cfe/v6/result.rb b/app/models/cfe/v6/result.rb index 8b4670610e..ac9c89255e 100644 --- a/app/models/cfe/v6/result.rb +++ b/app/models/cfe/v6/result.rb @@ -1,6 +1,33 @@ module CFE module V6 class Result < CFE::V4::Result + def gross_income_results + gross_income_proceeding_types.pluck(:result) + end + + def disposable_income_results + disposable_income_proceeding_types.pluck(:result) + end + + def capital_proceeding_types + capital_summary[:proceeding_types] + end + + def capital_results + capital_proceeding_types.pluck(:result) + end + + def ineligible_gross_income? + gross_income_results.all?("ineligible") + end + + def ineligible_disposable_income? + disposable_income_results.all?("ineligible") + end + + def ineligible_disposable_capital? + capital_results.all?("ineligible") + end end end end diff --git a/app/views/shared/assessment_results/_ineligible.html.erb b/app/views/shared/assessment_results/_ineligible.html.erb index 50e7c2b143..a407bbcb9d 100644 --- a/app/views/shared/assessment_results/_ineligible.html.erb +++ b/app/views/shared/assessment_results/_ineligible.html.erb @@ -4,6 +4,6 @@
-

<%= t(".detail") %>

+

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

diff --git a/config/locales/en/shared.yml b/config/locales/en/shared.yml index 068ab49d5e..7a4aa215e8 100644 --- a/config/locales/en/shared.yml +++ b/config/locales/en/shared.yml @@ -105,7 +105,7 @@ en: - You still need to provide details of the case before we can decide if they’re eligible. ineligible: heading: "%{name} is unlikely to get legal aid" - detail: This is because they have too much disposable capital. + detail: "This is because they have too much %{ineligible_reasons}" capital_contribution_required: heading: "%{name} may need to pay towards legal aid" details: @@ -922,3 +922,7 @@ en: details: | For example, Child Benefit or tax credits. Do not include Housing Benefit, government Cost of Living Payments, or any other disregarded benefits. + ineligible_reasons: + gross_income: gross income + disposable_income: disposable income + disposable_capital: disposable capital diff --git a/spec/factories/cfe_results/v6/mock_results.rb b/spec/factories/cfe_results/v6/mock_results.rb new file mode 100644 index 0000000000..f89d1b7937 --- /dev/null +++ b/spec/factories/cfe_results/v6/mock_results.rb @@ -0,0 +1,619 @@ +module CFEResults + module V6 + class MockResults + def self.eligible + { + version: "6", + timestamp: "2021-05-26T12:51:56.329Z", + success: true, + result_summary: { + overall_result: { + result: "eligible", + capital_contribution: 0.0, + income_contribution: 0.0, + matter_types: [{ + matter_type: "domestic_abuse", + result: "eligible", + }], + proceeding_types: [ + { + ccms_code: "DA006", + result: "eligible", + }, + { + ccms_code: "DA002", + result: "eligible", + }, + ], + }, + gross_income: { + total_gross_income: 0.0, + proceeding_types: [ + { + ccms_code: "DA006", + upper_threshold: 999_999_999_999.0, + result: "pending", + }, + { + ccms_code: "DA002", + upper_threshold: 999_999_999_999.0, + result: "pending", + }, + ], + }, + disposable_income: { + dependant_allowance: 0.0, + gross_housing_costs: 0.0, + housing_benefit: 0.0, + net_housing_costs: 125.0, + maintenance_allowance: 0.0, + total_outgoings_and_allowances: 0.0, + total_disposable_income: 0.0, + income_contribution: 0.0, + employment_income: { + gross_income: 2143.97, + benefits_in_kind: 0.0, + tax: -204.15, + national_insurance: -161.64, + fixed_employment_deduction: -45.0, + net_employment_income: 1778.18, + }, + proceeding_types: [ + { + ccms_code: "DA006", + upper_threshold: 999_999_999_999.0, + lower_threshold: 315.0, + result: "pending", + }, + { + ccms_code: "DA002", + upper_threshold: 999_999_999_999.0, + lower_threshold: 315.0, + result: "pending", + }, + ], + }, + capital: { + total_liquid: 12.0, + total_non_liquid: 12.0, + total_vehicle: 120.0, + total_property: 0.0, + total_mortgage_allowance: 999_999_999_999.0, + total_capital: 144.0, + pensioner_capital_disregard: 0.0, + capital_contribution: 0.0, + assessed_capital: 144.0, + proceeding_types: [ + { + ccms_code: "DA006", + lower_threshold: 3000.0, + upper_threshold: 999_999_999_999.0, + result: "eligible", + }, + { + ccms_code: "DA002", + lower_threshold: 3000.0, + upper_threshold: 999_999_999_999.0, + result: "eligible", + }, + ], + }, + }, + assessment: { + id: "b60d9312-b77b-4c5f-aa79-ba8508800c59", + client_reference_id: "L-C36-J5T", + submission_date: "2021-05-26", + applicant: { + date_of_birth: "1980-01-10", + involvement_type: "applicant", + has_partner_opponent: false, + receives_qualifying_benefit: true, + self_employed: false, + }, + gross_income: { + irregular_income: { + monthly_equivalents: { + student_loan: 0.0, + }, + }, + state_benefits: { + monthly_equivalents: { + all_sources: 75.0, + cash_transactions: 0.0, + bank_transactions: [], + }, + }, + other_income: { + monthly_equivalents: { + all_sources: { + friends_or_family: 0.0, + maintenance_in: 0.0, + property_or_lodger: 0.0, + pension: 0.0, + }, + bank_transactions: { + friends_or_family: 0.0, + maintenance_in: 0.0, + property_or_lodger: 0.0, + pension: 0.0, + }, + cash_transactions: { + friends_or_family: 0.0, + maintenance_in: 0.0, + property_or_lodger: 0.0, + pension: 0.0, + }, + }, + }, + }, + disposable_income: { + monthly_equivalents: { + all_sources: { + child_care: 0.0, + rent_or_mortgage: 125.0, + maintenance_out: 0.0, + legal_aid: 0.0, + }, + bank_transactions: { + child_care: 0.0, + rent_or_mortgage: 0.0, + maintenance_out: 0.0, + legal_aid: 0.0, + }, + cash_transactions: { + child_care: 0.0, + rent_or_mortgage: 0.0, + maintenance_out: 0.0, + legal_aid: 0.0, + }, + }, + childcare_allowance: 0.0, + deductions: { + dependants_allowance: 0.0, + disregarded_state_benefits: 0.0, + }, + }, + capital: { + capital_items: { + liquid: [ + { + description: "Current accounts", + value: 1.0, + }, + { + description: "Savings accounts", + value: 1.0, + }, + { + description: "Money not in a bank account", + value: 10.0, + }, + { + description: "Online current accounts", + value: 0.0, + }, + { + description: "Online savings accounts", + value: 0.0, + }, + ], + non_liquid: [{ + description: "Interest in a trust", + value: 12.0, + }], + vehicles: [ + { + value: 120.0, + loan_amount_outstanding: 12.0, + date_of_purchase: "2017-05-26", + in_regular_use: false, + included_in_assessment: true, + assessed_value: 120.0, + }, + ], + properties: { + main_home: { + value: 10.0, + outstanding_mortgage: 20.0, + percentage_owned: 10.0, + main_home: true, + shared_with_housing_assoc: true, + transaction_allowance: 0.3, + allowable_outstanding_mortgage: 20.0, + net_value: -10.3, + net_equity: -19.3, + main_home_equity_disregard: 100_000.0, + assessed_equity: 0.0, + }, + additional_properties: [ + { + value: 0.0, + outstanding_mortgage: 0.0, + percentage_owned: 0.0, + main_home: false, + shared_with_housing_assoc: false, + transaction_allowance: 0.0, + allowable_outstanding_mortgage: 0.0, + net_value: 0.0, + net_equity: 0.0, + main_home_equity_disregard: 0.0, + assessed_equity: 0.0, + }, + ], + }, + }, + }, + remarks: {}, + }, + } + end + + def self.ineligible_gross_income + result = eligible + result[:result_summary][:overall_result][:result] = "ineligible" + result[:result_summary][:gross_income] = { + total_gross_income: 43_333.33, + proceeding_types: [ + { + ccms_code: "SE097A", + upper_threshold: 2657.0, + lower_threshold: 0.0, + result: "ineligible", + client_involvement_type: "A", + }, + { + ccms_code: "SE101E", + upper_threshold: 2657.0, + lower_threshold: 0.0, + result: "ineligible", + client_involvement_type: "A", + }, + ], + combined_total_gross_income: 43_333.33, + } + 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: 0.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: "SE097A", + upper_threshold: 733.0, + lower_threshold: 315.0, + result: "pending", + client_involvement_type: "A", + }, + { + ccms_code: "SE101E", + upper_threshold: 733.0, + lower_threshold: 315.0, + result: "pending", + client_involvement_type: "A", + }, + ], + combined_total_disposable_income: 0.0, + combined_total_outgoings_and_allowances: 0.0, + partner_allowance: 0, + lone_parent_allowance: 0, + income_contribution: 0, + } + result[:result_summary][:capital] = { + pensioner_disregard_applied: 0.0, + total_liquid: 0.0, + total_non_liquid: 0.0, + total_vehicle: 0.0, + total_property: 0.0, + total_mortgage_allowance: 0.0, + total_capital: 0.0, + subject_matter_of_dispute_disregard: 0.0, + assessed_capital: 0.0, + total_capital_with_smod: 0, + disputed_non_property_disregard: 0, + proceeding_types: [ + { + ccms_code: "SE097A", + upper_threshold: 8000.0, + lower_threshold: 3000.0, + result: "pending", + client_involvement_type: "A", + }, + { + ccms_code: "SE101E", + upper_threshold: 8000.0, + lower_threshold: 3000.0, + result: "pending", + client_involvement_type: "A", + }, + ], + combined_disputed_capital: 0, + combined_non_disputed_capital: 0, + capital_contribution: 0.0, + pensioner_capital_disregard: 0.0, + combined_assessed_capital: 0.0, + } + result + end + + def self.ineligible_capital + result = eligible + result[:result_summary][:overall_result][:result] = "ineligible" + result[:result_summary][:gross_income] = { + total_gross_income: 0.0, + proceeding_types: [ + { ccms_code: "SE097A", + 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: 0.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: 0.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: "SE097A", + upper_threshold: 733.0, + lower_threshold: 315.0, + result: "eligible", + client_involvement_type: "A" }, + { ccms_code: "SE101E", + upper_threshold: 733.0, + lower_threshold: 315.0, + result: "eligible", + client_involvement_type: "A" }, + ], + combined_total_disposable_income: 0.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 + + def self.ineligible_disposable_income + 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: 0.0, + total_non_liquid: 0.0, + total_vehicle: 0.0, + total_property: 0.0, + total_mortgage_allowance: 0.0, + total_capital: 0.0, + subject_matter_of_dispute_disregard: 0.0, + assessed_capital: 0.0, + total_capital_with_smod: 0, + disputed_non_property_disregard: 0, + proceeding_types: [{ ccms_code: "SE100E", + upper_threshold: 8000.0, + lower_threshold: 3000.0, + result: "pending", + client_involvement_type: "A" }, + { ccms_code: "SE101E", + upper_threshold: 8000.0, + lower_threshold: 3000.0, + result: "pending", + client_involvement_type: "A" }], + combined_disputed_capital: 0, + combined_non_disputed_capital: 0, + capital_contribution: 0.0, + pensioner_capital_disregard: 0.0, + combined_assessed_capital: 0.0, + } + result + end + + # This result has has been faked, to cover an example where CFE returns 'ineligible' + # for more than one proceeding category, which is currently not possible. + # Currently, for example, 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 his is not currently not happening as there is a CFE ticket to introduce + # this functionality. See https://dsdmoj.atlassian.net/browse/LEP-349 + 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 new file mode 100644 index 0000000000..b0c00e786b --- /dev/null +++ b/spec/factories/cfe_results/v6/results.rb @@ -0,0 +1,28 @@ +module CFEResults + module V6 + FactoryBot.define do + factory :cfe_v6_result, class: "CFE::V6::Result" do + submission factory: :cfe_submission + legal_aid_application { submission.legal_aid_application } + result { CFEResults::V5::MockResults.eligible.to_json } + type { "CFE::V6::Result" } + + trait :ineligible_gross_income do + result { CFEResults::V6::MockResults.ineligible_gross_income.to_json } + end + + trait :ineligible_disposable_income do + result { CFEResults::V6::MockResults.ineligible_disposable_income.to_json } + end + + 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 +end diff --git a/spec/helpers/ineligible_reasons_helper_spec.rb b/spec/helpers/ineligible_reasons_helper_spec.rb new file mode 100644 index 0000000000..24c7155e8f --- /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/models/cfe/v6/result_spec.rb b/spec/models/cfe/v6/result_spec.rb new file mode 100644 index 0000000000..f67f3aebb9 --- /dev/null +++ b/spec/models/cfe/v6/result_spec.rb @@ -0,0 +1,96 @@ +require "rails_helper" + +module CFE + module V6 + RSpec.describe Result do + let(:cfe_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) } + + describe "#gross_income_results" do + context "when overall result is eligible" do + it "returns pending for each proceeding" do + expect(cfe_result.gross_income_results).to eq %w[pending pending] + end + end + + context "when overall result is ineligible because gross income is above upper threshold" do + it "returns ineligible for each proceeding" do + expect(ineligible_gross_income_result.gross_income_results).to eq %w[ineligible ineligible] + end + end + end + + describe "#disposable_income_results" do + context "when overall result is eligible" do + it "returns pending for each proceeding" do + expect(cfe_result.disposable_income_results).to eq %w[pending pending] + end + end + + context "when overall result is ineligible because disposable income is above upper threshold" do + it "returns ineligible for each proceeding" do + expect(ineligible_disposable_income_result.disposable_income_results).to eq %w[ineligible ineligible] + end + end + end + + describe "#capital_results" do + context "when overall result is eligible" do + it "returns eligible for each proceeding" do + expect(cfe_result.capital_results).to eq %w[eligible eligible] + end + end + + context "when overall result is ineligible because disposable capital is above upper threshold" do + it "returns ineligible for each proceeding" do + expect(ineligible_capital_result.capital_results).to eq %w[ineligible ineligible] + end + end + end + + describe "#ineligible_gross_income?" do + context "when overall result is eligible" do + it "returns false" do + expect(cfe_result.ineligible_gross_income?).to be false + end + end + + context "when overall result is ineligible because gross income is above upper threshold" do + it "returns true" do + expect(ineligible_gross_income_result.ineligible_gross_income?).to be true + end + end + end + + describe "#ineligible_disposable_income?" do + context "when overall result is eligible" do + it "returns false" do + expect(cfe_result.ineligible_disposable_income?).to be false + end + end + + context "when overall result is ineligible because disposable income is above upper threshold" do + it "returns true" do + expect(ineligible_disposable_income_result.ineligible_disposable_income?).to be true + end + end + end + + describe "#ineligible_disposable_capital?" do + context "when overall result is eligible" do + it "returns false" do + expect(cfe_result.ineligible_disposable_capital?).to be false + end + end + + context "when overall result is ineligible because disposable income is above upper threshold" do + it "returns true" do + expect(ineligible_capital_result.ineligible_disposable_capital?).to be true + end + end + 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 5de03ab539..14980dd93a 100644 --- a/spec/requests/providers/capital_assessment_results_controller_spec.rb +++ b/spec/requests/providers/capital_assessment_results_controller_spec.rb @@ -36,15 +36,19 @@ 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) end it "displays the correct result" do - expect(unescaped_response_body).to include(I18n.t("ineligible.heading", name: applicant_name, scope: locale_scope)) + expect(unescaped_response_body).to include("#{applicant_name} is unlikely to get legal aid") + end + + it "displays the correct reason" do + expect(unescaped_response_body).to include("This is because they have too much disposable capital") end end @@ -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 13ae4e3a17..68475b5306 100644 --- a/spec/requests/providers/capital_income_assessment_results_controller_spec.rb +++ b/spec/requests/providers/capital_income_assessment_results_controller_spec.rb @@ -38,14 +38,36 @@ end context "when not eligible" do - let(:cfe_result) { create(:cfe_v4_result, :not_eligible) } + 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 - expect(response).to have_http_status(:ok) + 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("#{applicant_name} is unlikely to get legal aid") + end + + it "displays the correct reason" do + expect(unescaped_response_body).to include("This is because they have too much gross income") + end end - it "displays the correct result" do - expect(unescaped_response_body).to include(I18n.t("ineligible.heading", name: applicant_name, scope: locale_scope)) + 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 + expect(response).to have_http_status(:ok) + end + + it "displays the correct result" do + expect(unescaped_response_body).to include("#{applicant_name} is unlikely to get legal aid") + end + + it "displays the correct reason" do + expect(unescaped_response_body).to include("This is because they have too much disposable income") + end end end @@ -108,14 +130,14 @@ end context "when not eligible" do - let(:cfe_result) { create(:cfe_v4_result, :not_eligible) } + let(:cfe_result) { create(:cfe_v6_result, :ineligible_gross_income) } 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)) + expect(unescaped_response_body).to include("#{applicant_name} is unlikely to get legal aid") end end