-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ap-4503: Add ineligible_reasons_helper to help with display of inelig…
…ible reasons
- Loading branch information
Showing
8 changed files
with
199 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters