From 99e2e04b2e92f282b7642ada47b1e2bf8b210772 Mon Sep 17 00:00:00 2001 From: Jack S Date: Thu, 6 Apr 2023 16:40:53 +0100 Subject: [PATCH] Use money flag --- .../lettings/pages/max_rent_value_check.rb | 3 +- .../lettings/pages/min_rent_value_check.rb | 8 ++- .../lettings/pages/net_income_value_check.rb | 4 +- .../sales/pages/about_price_value_check.rb | 1 + .../pages/discounted_sale_value_check.rb | 4 +- .../shared_ownership_deposit_value_check.rb | 1 + config/locales/en.yml | 14 ++--- .../pages/max_rent_value_check_spec.rb | 37 +++++++++++++ .../pages/min_rent_value_check_spec.rb | 48 +++++++++++++++++ .../pages/net_income_value_check_spec.rb | 40 ++++++++++++++ .../pages/about_price_value_check_spec.rb | 54 +++++++++++++++++++ .../pages/discounted_sale_value_check_spec.rb | 4 +- ...ared_ownership_deposit_value_check_spec.rb | 8 +-- .../lettings_logs_import_service_spec.rb | 10 ++-- 14 files changed, 209 insertions(+), 27 deletions(-) create mode 100644 spec/models/form/lettings/pages/max_rent_value_check_spec.rb create mode 100644 spec/models/form/lettings/pages/min_rent_value_check_spec.rb create mode 100644 spec/models/form/lettings/pages/net_income_value_check_spec.rb create mode 100644 spec/models/form/sales/pages/about_price_value_check_spec.rb diff --git a/app/models/form/lettings/pages/max_rent_value_check.rb b/app/models/form/lettings/pages/max_rent_value_check.rb index 59b2d14fe..007d90c77 100644 --- a/app/models/form/lettings/pages/max_rent_value_check.rb +++ b/app/models/form/lettings/pages/max_rent_value_check.rb @@ -5,7 +5,7 @@ class Form::Lettings::Pages::MaxRentValueCheck < ::Form::Page @depends_on = [{ "rent_in_soft_max_range?" => true }] @title_text = { "translation" => "soft_validations.rent.outside_range_title", - "arguments" => [{ "key" => "brent", "label" => true, "i18n_template" => "brent" }], + "arguments" => [{ "key" => "brent", "label" => true, "i18n_template" => "brent", "money" => true }], } @informative_text = { "translation" => "soft_validations.rent.max_hint_text", @@ -14,6 +14,7 @@ class Form::Lettings::Pages::MaxRentValueCheck < ::Form::Page "key" => "soft_max_for_period", "label" => false, "i18n_template" => "soft_max_for_period", + "money" => true, }, ], } diff --git a/app/models/form/lettings/pages/min_rent_value_check.rb b/app/models/form/lettings/pages/min_rent_value_check.rb index ed5ede781..e48e89fe4 100644 --- a/app/models/form/lettings/pages/min_rent_value_check.rb +++ b/app/models/form/lettings/pages/min_rent_value_check.rb @@ -5,7 +5,12 @@ class Form::Lettings::Pages::MinRentValueCheck < ::Form::Page @depends_on = [{ "rent_in_soft_min_range?" => true }] @title_text = { "translation" => "soft_validations.rent.outside_range_title", - "arguments" => [{ "key" => "brent", "label" => true, "i18n_template" => "brent" }], + "arguments" => [{ + "key" => "brent", + "label" => true, + "i18n_template" => "brent", + "money" => true, + }], } @informative_text = { "translation" => "soft_validations.rent.min_hint_text", @@ -14,6 +19,7 @@ class Form::Lettings::Pages::MinRentValueCheck < ::Form::Page "key" => "soft_min_for_period", "label" => false, "i18n_template" => "soft_min_for_period", + "money" => true, }, ], } diff --git a/app/models/form/lettings/pages/net_income_value_check.rb b/app/models/form/lettings/pages/net_income_value_check.rb index 9a9c1061f..511667695 100644 --- a/app/models/form/lettings/pages/net_income_value_check.rb +++ b/app/models/form/lettings/pages/net_income_value_check.rb @@ -7,8 +7,8 @@ class Form::Lettings::Pages::NetIncomeValueCheck < ::Form::Page @informative_text = { "translation" => "soft_validations.net_income.hint_text", "arguments" => [ - { "key" => "ecstat1", "label" => true, "i18n_template" => "ecstat1" }, - { "key" => "earnings", "label" => true, "i18n_template" => "earnings" }, + { "key" => "ecstat1", "label" => true, "i18n_template" => "ecstat1", "money" => true }, + { "key" => "earnings", "label" => true, "i18n_template" => "earnings", "money" => true }, ], } end diff --git a/app/models/form/sales/pages/about_price_value_check.rb b/app/models/form/sales/pages/about_price_value_check.rb index 94df02243..fa2f54891 100644 --- a/app/models/form/sales/pages/about_price_value_check.rb +++ b/app/models/form/sales/pages/about_price_value_check.rb @@ -13,6 +13,7 @@ class Form::Sales::Pages::AboutPriceValueCheck < ::Form::Page "key" => "value", "label" => true, "i18n_template" => "value", + "money" => true, }, ], } diff --git a/app/models/form/sales/pages/discounted_sale_value_check.rb b/app/models/form/sales/pages/discounted_sale_value_check.rb index 8ff48a0bd..c77a70f60 100644 --- a/app/models/form/sales/pages/discounted_sale_value_check.rb +++ b/app/models/form/sales/pages/discounted_sale_value_check.rb @@ -4,11 +4,11 @@ class Form::Sales::Pages::DiscountedSaleValueCheck < ::Form::Page @depends_on = depends_on @title_text = { "translation" => "soft_validations.discounted_sale_value.title_text", - "arguments" => [{ "key" => "value_with_discount", "label" => false, "i18n_template" => "value_with_discount" }], + "arguments" => [{ "key" => "value_with_discount", "label" => false, "i18n_template" => "value_with_discount", "money" => true }], } @informative_text = { "translation" => "soft_validations.discounted_sale_value.informative_text", - "arguments" => [{ "key" => "mortgage_deposit_and_grant_total", "label" => false, "i18n_template" => "mortgage_deposit_and_grant_total" }], + "arguments" => [{ "key" => "mortgage_deposit_and_grant_total", "label" => false, "i18n_template" => "mortgage_deposit_and_grant_total", "money" => true }], } @person_index = person_index @depends_on = [ diff --git a/app/models/form/sales/pages/shared_ownership_deposit_value_check.rb b/app/models/form/sales/pages/shared_ownership_deposit_value_check.rb index be2126482..861cc6cf5 100644 --- a/app/models/form/sales/pages/shared_ownership_deposit_value_check.rb +++ b/app/models/form/sales/pages/shared_ownership_deposit_value_check.rb @@ -14,6 +14,7 @@ class Form::Sales::Pages::SharedOwnershipDepositValueCheck < ::Form::Page "key" => "expected_shared_ownership_deposit_value", "label" => false, "i18n_template" => "expected_shared_ownership_deposit_value", + "money" => true, }, ], } diff --git a/config/locales/en.yml b/config/locales/en.yml index e223c7fc9..44f4a3e87 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -283,7 +283,7 @@ en: general_needs: "Enter a value for the support charge between £0 and £60 per week if the landlord is a local authority and it is a general needs letting" supported_housing: "Enter a value for the support charge between £0 and £120 per week if the landlord is a local authority and it is a supported housing letting" ecstat: - over_hard_max: "Net income of £%{hard_max} per week is too high for given the tenant’s working situation" + over_hard_max: "Net income of %{hard_max} per week is too high for given the tenant’s working situation" brent: below_hard_min: "Rent is below the absolute minimum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms" above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms" @@ -314,7 +314,7 @@ en: charges: complete_1_of_3: "Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’" tcharge: - under_10: "Enter a total charge that is at least £10 per week" + under_10: "Enter a total charge that is at least £10.00 per week" rent_period: invalid_for_org: "%{org_name} does not charge rent %{rent_period}" carehome: @@ -516,8 +516,8 @@ en: under_soft_min_for_economic_status: "You said income was %{income}, which is below this working situation's minimum (%{minimum})" rent: outside_range_title: "You told us the rent is %{brent}" - min_hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}." - max_hint_text: "The maximum rent expected for this type of property in this local authority is £%{soft_max_for_period}." + min_hint_text: "The minimum rent expected for this type of property in this local authority is %{soft_min_for_period}." + max_hint_text: "The maximum rent expected for this type of property in this local authority is %{soft_max_for_period}." purchase_price: title_text: "You told us the purchase price is %{value}" hint_text: "The %{min_or_max} purchase price expected for this type of property in this local authority is %{soft_min_or_soft_max}" @@ -539,7 +539,7 @@ en: void_date: title_text: "You told us the time between the start of the tenancy and the void date is more than 2 years" shared_ownership_deposit: - title_text: "Mortgage, deposit and cash discount total should equal £%{expected_shared_ownership_deposit_value}" + title_text: "Mortgage, deposit and cash discount total should equal %{expected_shared_ownership_deposit_value}" old_persons_shared_ownership: "At least one buyer should be aged over 64 for Older persons’ shared ownership scheme" staircase_bought_seems_high: "You said %{percentage}% was bought in this staircasing transaction, which seems high. Are you sure?" monthly_charges_over_soft_max: @@ -547,8 +547,8 @@ en: student_not_child: title_text: "You told us this person is a student aged beween 16 and 19" discounted_sale_value: - title_text: "Mortgage, deposit, and grant total must equal £%{value_with_discount}" - informative_text: "Your given mortgage, deposit and grant total is £%{mortgage_deposit_and_grant_total}" + title_text: "Mortgage, deposit, and grant total must equal %{value_with_discount}" + informative_text: "Your given mortgage, deposit and grant total is %{mortgage_deposit_and_grant_total}" care_home_charges: title_text: "Care home charges should be provided if this is a care home accommodation" diff --git a/spec/models/form/lettings/pages/max_rent_value_check_spec.rb b/spec/models/form/lettings/pages/max_rent_value_check_spec.rb new file mode 100644 index 000000000..034b14e3a --- /dev/null +++ b/spec/models/form/lettings/pages/max_rent_value_check_spec.rb @@ -0,0 +1,37 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::MaxRentValueCheck, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { "shared_ownership_deposit_value_check" } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[rent_value_check]) + end + + it "has the correct id" do + expect(page.id).to eq("max_rent_value_check") + end + + it "has the correct header" do + expect(page.header).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "rent_in_soft_max_range?" => true }]) + end + + it "has the correct title_text" do + expect(page.title_text).to eq({ "arguments" => [{ "i18n_template" => "brent", "key" => "brent", "label" => true, "money" => true }], "translation" => "soft_validations.rent.outside_range_title" }) + end + + it "has the correct informative_text" do + expect(page.informative_text).to eq({ "arguments" => [{ "i18n_template" => "soft_max_for_period", "key" => "soft_max_for_period", "label" => false, "money" => true }], "translation" => "soft_validations.rent.max_hint_text" }) + end +end diff --git a/spec/models/form/lettings/pages/min_rent_value_check_spec.rb b/spec/models/form/lettings/pages/min_rent_value_check_spec.rb new file mode 100644 index 000000000..402f8c589 --- /dev/null +++ b/spec/models/form/lettings/pages/min_rent_value_check_spec.rb @@ -0,0 +1,48 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::MinRentValueCheck, type: :model do + subject(:page) { described_class.new(nil, page_definition, subsection) } + + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has the correct header" do + expect(page.header).to be nil + end + + it "has the correct description" do + expect(page.description).to be nil + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[rent_value_check]) + end + + it "has the correct id" do + expect(page.id).to eq("min_rent_value_check") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "rent_in_soft_min_range?" => true }], + ) + end + + it "has the correct title_text" do + expect(page.title_text).to eq({ + "translation" => "soft_validations.rent.outside_range_title", + "arguments" => [{ "i18n_template" => "brent", "key" => "brent", "label" => true, "money" => true }], + }) + end + + it "has the correct informative_text" do + expect(page.informative_text).to eq({ + "arguments" => [{ "i18n_template" => "soft_min_for_period", "key" => "soft_min_for_period", "label" => false, "money" => true }], + "translation" => "soft_validations.rent.min_hint_text", + }) + end +end diff --git a/spec/models/form/lettings/pages/net_income_value_check_spec.rb b/spec/models/form/lettings/pages/net_income_value_check_spec.rb new file mode 100644 index 000000000..194fcdd35 --- /dev/null +++ b/spec/models/form/lettings/pages/net_income_value_check_spec.rb @@ -0,0 +1,40 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::NetIncomeValueCheck, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { "shared_ownership_deposit_value_check" } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[net_income_value_check]) + end + + it "has the correct id" do + expect(page.id).to eq("net_income_value_check") + end + + it "has the correct header" do + expect(page.header).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "net_income_soft_validation_triggered?" => true }]) + end + + it "has the correct title_text" do + expect(page.title_text).to eq({ "translation" => "soft_validations.net_income.title_text" }) + end + + it "has the correct informative_text" do + expect(page.informative_text).to eq({ + "arguments" => [{ "i18n_template" => "ecstat1", "key" => "ecstat1", "label" => true, "money" => true }, { "i18n_template" => "earnings", "key" => "earnings", "label" => true, "money" => true }], + "translation" => "soft_validations.net_income.hint_text", + }) + end +end diff --git a/spec/models/form/sales/pages/about_price_value_check_spec.rb b/spec/models/form/sales/pages/about_price_value_check_spec.rb new file mode 100644 index 000000000..abfb9931e --- /dev/null +++ b/spec/models/form/sales/pages/about_price_value_check_spec.rb @@ -0,0 +1,54 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::AboutPriceValueCheck, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { "savings_value_check" } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[value_value_check]) + end + + it "has the correct id" do + expect(page.id).to eq("savings_value_check") + end + + it "has the correct header" do + expect(page.header).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "purchase_price_out_of_soft_range?" => true }]) + end + + it "is interruption screen page" do + expect(page.interruption_screen?).to eq(true) + end + + it "has the correct title_text" do + expect(page.title_text).to eq({ "arguments" => [{ "i18n_template" => "value", "key" => "value", "label" => true, "money" => true }], "translation" => "soft_validations.purchase_price.title_text" }) + end + + it "has the correct informative_text" do + expect(page.informative_text).to eq({ + "translation" => "soft_validations.purchase_price.hint_text", + "arguments" => [ + { + "key" => "field_formatted_as_currency", + "arguments_for_key" => "purchase_price_soft_min_or_soft_max", + "i18n_template" => "soft_min_or_soft_max", + }, + { + "key" => "purchase_price_min_or_max_text", + "i18n_template" => "min_or_max", + }, + ], + }) + end +end diff --git a/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb b/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb index ddd4bc33c..275e5d0a3 100644 --- a/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb +++ b/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb @@ -27,14 +27,14 @@ RSpec.describe Form::Sales::Pages::DiscountedSaleValueCheck, type: :model do it "has the correct title_text" do expect(page.title_text).to eq({ "translation" => "soft_validations.discounted_sale_value.title_text", - "arguments" => [{ "key" => "value_with_discount", "label" => false, "i18n_template" => "value_with_discount" }], + "arguments" => [{ "key" => "value_with_discount", "label" => false, "i18n_template" => "value_with_discount", "money" => true }], }) end it "has the correct informative_text" do expect(page.informative_text).to eq({ "translation" => "soft_validations.discounted_sale_value.informative_text", - "arguments" => [{ "key" => "mortgage_deposit_and_grant_total", "label" => false, "i18n_template" => "mortgage_deposit_and_grant_total" }], + "arguments" => [{ "key" => "mortgage_deposit_and_grant_total", "label" => false, "i18n_template" => "mortgage_deposit_and_grant_total", "money" => true }], }) end diff --git a/spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb b/spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb index 893a5cb5b..a3b2bfa07 100644 --- a/spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb +++ b/spec/models/form/sales/pages/shared_ownership_deposit_value_check_spec.rb @@ -34,13 +34,7 @@ RSpec.describe Form::Sales::Pages::SharedOwnershipDepositValueCheck, type: :mode it "has the correct title_text" do expect(page.title_text).to eq({ "translation" => "soft_validations.shared_ownership_deposit.title_text", - "arguments" => [ - { - "key" => "expected_shared_ownership_deposit_value", - "label" => false, - "i18n_template" => "expected_shared_ownership_deposit_value", - }, - ], + "arguments" => [{ "i18n_template" => "expected_shared_ownership_deposit_value", "key" => "expected_shared_ownership_deposit_value", "label" => false, "money" => true }], }) end diff --git a/spec/services/imports/lettings_logs_import_service_spec.rb b/spec/services/imports/lettings_logs_import_service_spec.rb index deccde0c0..fb5c1227c 100644 --- a/spec/services/imports/lettings_logs_import_service_spec.rb +++ b/spec/services/imports/lettings_logs_import_service_spec.rb @@ -532,11 +532,11 @@ RSpec.describe Imports::LettingsLogsImportService do end it "intercepts the relevant validation error" do - expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing brent with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10 per week") - expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing scharge with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10 per week") - expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing pscharge with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10 per week") - expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing supcharg with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10 per week") - expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing tcharge with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10 per week") + expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing brent with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week") + expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing scharge with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week") + expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing pscharge with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week") + expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing supcharg with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week") + expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing tcharge with error: Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’, Enter a total charge that is at least £10.00 per week") expect { lettings_log_service.send(:create_log, lettings_log_xml) } .not_to raise_error end